當前位置:首頁 » 操作系統 » 資料庫登錄驗證

資料庫登錄驗證

發布時間: 2023-05-09 15:57:45

Ⅰ 用資料庫怎樣驗證賬號和密碼

你要首先連庫,要確定連上了!然後再用sql語句選擇,就可以了,你要先選擇用戶
分別用兩個變數來保存選擇的結果
select
name
from
user
where
user.username='textFiled1.text'
這個驗證這個賬戶存不存在
然後用戶存在的時候再驗證密碼:
既然樓主可以做出界面的話,相信樓主可以寫好這個代碼咯,樓主加油吧

java鏈接mysql資料庫實現登陸驗證

//這是我以前寫的核對資料庫實現登陸的方法,你只看jdbc部分就好,我還特地給你加了點注釋
String sql = "select username,password from account";
String user = request.getParameter("user");
String pass = request.getParameter("password");
int j = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JDBCTools1.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
//從表中查詢獲取所有賬戶的用戶名&密碼的ResultSet 對象
while(rs.next()){
int i = 0;

String username[] = new String[10];//用戶名數組
String password[] = new String[10];//密碼數組
username[i] = rs.getString(1);
password[i] = rs.getString(2);
if(user.equals(username[i])&&pass.equals(password[i])){//比對
response.getWriter().print("you are welcome!");
j++;
}else if(user.equals(username[i])&&!pass.equals(password[i])){
response.getWriter().println("the realy password is :"+ username[i] +","+password[i]+"\r\n");
response.getWriter().println("and you password is :"+user +","+pass+" :so the username or password may not right");
j++;
}else{
continue;
}
i++;
}
if(j == 0){
response.getWriter().println("Your username may not be properly");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
JDBCTools1.release(rs, ps, conn);
}
//這是我JDBCTools的getConnection方法
getConnection{
String driverClass = oracle.jdbc.driver.OracleDriver;
String jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl;
//你的資料庫的用戶名密碼
String user = null;
String password = null;
// 通過反射創建Driver對象
Class.forName(driverClass);
return DriverManager.getConnection(jdbcUrl, user, password);}
//這是我JDBCTools的release方法
public static void release(ResultSet rs, Statement statement,
Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

if (statement != null) {
try {
statement.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}

if (conn != null) {
try {
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}

Ⅲ SQL Server 2005資料庫有幾種登錄驗證方式

兩種
Windows身份驗證臘段和SQL Server身份高局中戚山驗證
希望可以幫助到你。

Ⅳ java鏈接mysql資料庫實現登陸如何驗證

//這是我以前寫的核對資料庫實現登陸的方法,你只看jdbc部分就好,我還特地給你加了點注釋x0dx0aString sql = "select username,password from account";x0dx0aString user = request.getParameter("user");x0dx0aString pass = request.getParameter("password");x0dx0aint j = 0;x0dx0aConnection conn = null;x0dx0aPreparedStatement ps = null;x0dx0aResultSet rs = null;x0dx0atry {x0dx0aconn = JDBCTools1.getConnection();x0dx0aps = conn.prepareStatement(sql);x0dx0ars = ps.executeQuery();x0dx0a//從表中查詢獲取所有賬戶的用戶名&密碼的ResultSet 對象x0dx0awhile(rs.next()){x0dx0aint i = 0;x0dx0ax0dx0aString username[] = new String[10];//用戶名數組x0dx0aString password[] = new String[10];//密碼數組x0dx0ausername[i] = rs.getString(1);x0dx0apassword[i] = rs.getString(2);x0dx0aif(user.equals(username[i])&&pass.equals(password[i])){//比對x0dx0aresponse.getWriter().print("you are welcome!");x0dx0aj++;x0dx0a}else if(user.equals(username[i])&&!pass.equals(password[i])){x0dx0aresponse.getWriter().println("the realy password is :"+ username[i] +","+password[i]+"\r\n");x0dx0aresponse.getWriter().println("and you password is :"+user +","+pass+" :so the username or password may not right");x0dx0aj++;x0dx0a}else{x0dx0acontinue;x0dx0a}x0dx0ai++;x0dx0a}x0dx0aif(j == 0){x0dx0aresponse.getWriter().println("Your username may not be properly");x0dx0a}x0dx0a} catch (Exception e) {x0dx0ae.printStackTrace();x0dx0a}finally{x0dx0aJDBCTools1.release(rs, ps, conn);x0dx0a}x0dx0a//這是我JDBCTools的getConnection方法x0dx0agetConnection{x0dx0aString driverClass = oracle.jdbc.driver.OracleDriver;x0dx0aString jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl;x0dx0a//你的資料庫的用戶名密碼x0dx0aString user = null;x0dx0aString password = null;x0dx0a// 通過反射創建Driver對象x0dx0aClass.forName(driverClass);x0dx0areturn DriverManager.getConnection(jdbcUrl, user, password);}x0dx0a//這是我JDBCTools的release方法x0dx0apublic static void release(ResultSet rs, Statement statement,x0dx0aConnection conn) {x0dx0aif (rs != null) {x0dx0atry {x0dx0ars.close();x0dx0a} catch (SQLException e) {x0dx0ae.printStackTrace();x0dx0a}x0dx0a}x0dx0ax0dx0aif (statement != null) {x0dx0atry {x0dx0astatement.close();x0dx0a} catch (Exception e2) {x0dx0ae2.printStackTrace();x0dx0a}x0dx0a}x0dx0ax0dx0aif (conn != null) {x0dx0atry {x0dx0aconn.close();x0dx0a} catch (Exception e2) {x0dx0ae2.printStackTrace();x0dx0a}x0dx0a}x0dx0a}

php資料庫驗證登陸

你記住 所有在 引號裡面的 東西都是字元串!!!!!

if("SELECT username,passwd FROM wen WHERE $username=$user,$passwd=$passwd"){
echo "<script>alert('歡迎登錄!');window.location.href='index1.php';</script>";
}
這一句代碼本身就是不通的.
還有就是 你的sql語句也是錯誤的。
參考如下:
$sql = 'SELECT username,passwd FROM wen WHERE username="'.$user.'" AND passwd="'.$passwd.'"';
$result = mysql_query($sql,$conn);

手動回復,不謝

Ⅵ 2008資料庫身份驗證忘了怎麼登錄進去

重置密碼。
進入資料庫確認身份,更改身份驗證,身份驗證更改確認,重新設置密碼。然後再登錄。
資料庫是「按照數據結構來組織、存儲和管理數據的倉庫」。是一個長期存儲在計算機內的、有組織的、可共享的、統一管理的大量數據的集合。

Ⅶ SQL資料庫 如何用SQL Server身份驗證 登陸

伺服器類型是你選擇登錄的資料庫類型、有資料庫引擎、analysis
services等等、一般自己用就用資料庫引擎。
伺服器名稱是你要連接到的資料庫伺服器名字、如果你不是遠程連的別的主機、就填你自己本機的名稱或者ip、或者用
.
表示、這是連接到本地計算機。選項里有網路設置、當你遠程連接別的主機時要調網路協議。
身份驗證sql有兩種模式、windows驗證不需要密碼、針對的是臨時應用。而sql驗證、登錄名08版本以前默認是sa、而08以後好像默認都是你自己計算機名、而密碼是你安裝sql時自己設置的。
你可以通過windows驗證進入sql、然後在左邊對象資源管理器里、最上面的大目錄右鍵、屬性、把sql驗證劃對勾選上。然後展開、安全性右鍵屬性、同樣勾上雙重驗證登錄許可。安全性展開、登錄名找到你的登錄名右鍵屬性、可以修改密碼和許可權。

Ⅷ 通過資料庫來驗證登錄用戶,怎麼實現驗證怎麼讀取數據

剛好上次講三層架構.有現成的例子

以一個驗證登陸為例子
這里是界面層一般叫UIL
protected void Button1_Click(object sender, EventArgs e)
{
List<User> Users = BAL.GetUserInfo(txtUserName.Text,txtPassword.Text);

if(Users.Length > 0)
{
Response.Write("登陸成功");
}
else
{
Response.Write("登陸失敗");
}
}

以下是邏輯層代碼,業務邏輯層一般叫BLL
public static List<User> GetUserInfo(string user,string password)
{
string newPassword = GetMD5Hash(password); //這里對密碼進行加密處理,資料庫中存放的是經過MD5加密後的密,業務邏輯層一般都是處理復雜的邏輯.例如加密邏輯
List<User> Users = DAL.GetUserInfo(user,newPassword);

return Users;
}

以下是數據訪問層代碼,數據訪問層一般叫DAL
public static List<User> GetUserInfo(string user,string password)
{
List<User> Users = new List<User>();
string sql = "select * from User where Password = '"+password+"' and User = '"+user+"'"; //寫where子句的時候把Password放前面.因為Password經過加密,所以可以防止SQL注入攻擊
SqlDataAdapter da = new SqlDataAdapter(sql,"這里是資料庫連接字元串");
DataSet ds = new DataSet();
da.Fill(ds);

for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
User user = new User(ds.Tables[0].Rows[i]["ID"].ToString(),ds.Tables[0].Rows[i]["User"].ToString(),ds.Tables[0].Rows[i]["Password"].ToString());
Users.Add(user);
}

return Users;
}

還會有一個Model層.叫做模板層.是數據表結構的印射.Model層是共用層,其他三層都要用到.
比如資料庫中有張表User,裡面有3個欄位ID,User,Password
那麼在模板層中應該有一個類,資料庫中User表的一行對應一個User對象,一張表對應User對象的集合.
public class User
{
string ID;
string User;
string Password;

//重載構造函數
User(string id,string user,string password)
{
this.ID=id;
this.User=user;
this.Password=password;
}
}

Ⅸ 登錄的用戶名怎麼驗證是資料庫的

利用 UserDetailsService 和PasswordEncoder 來驗證。
UserDetails 是由 UserDetailsService 返回的,由 DaoAuthenticationProvider 來驗證手蠢 UserDetails,然後返回一個 Authentication
這個 Authentication 持有一個 principal
這個 principal 就是 UserDetailsService 返回的 UserDetails
DaoAuthenticationProvider 是 AuthenticationProvider 介面的一種實現,
DaoAuthenticationProvider 用 UserDetailsService 來獲取用於比對的、真實正確的用戶名、密碼等信息。
Spring Security 對 UserDetailsService 介面默認提供了 in-memory 和 JDBC 兩種實現
為了自畢磨陪定義認證,要暴露出一個自己實現的 UserDetailsService Bean
密碼加密由 PasswordEncoder 處理,可以暴露一個 PasswordEncoder Bean 來定製
DaoAuthenticationProvider 是 AuthenticationProvider 介面的一種實游扮現,利用 UserDetailsService 和 PasswordEncoder 來認證一對用戶名密碼

熱點內容
python中ord函數 發布:2025-05-16 10:14:25 瀏覽:339
電腦啟動後無法連接伺服器 發布:2025-05-16 10:06:39 瀏覽:983
jar包編譯過程 發布:2025-05-16 10:03:37 瀏覽:678
選舉源碼 發布:2025-05-16 09:58:59 瀏覽:748
超級訪問陳小春應采兒 發布:2025-05-16 09:43:29 瀏覽:478
緩存視頻合並工具最新版 發布:2025-05-16 09:35:03 瀏覽:194
花雨庭伺服器ip地址和埠 發布:2025-05-16 09:34:58 瀏覽:239
同時修改多台伺服器管理地址工具 發布:2025-05-16 09:20:36 瀏覽:421
什麼配置就能玩地平線 發布:2025-05-16 09:13:46 瀏覽:82
python旋轉圖片 發布:2025-05-16 09:13:40 瀏覽:638