資料庫密碼驗證
① .net連接資料庫驗證用戶名,密碼是否正確
1.看連接字元串是否正確
Provider=sqlOLEDB.1;Persist Security Info=False;User ID=用戶名;Initial Catalog=資料庫;Data Source=. //密碼為空
如果只裝了一個版本的sql,可以簡化成萬能的連接字元串
User ID=用戶名;Initial Catalog=資料庫;Data Source=.
2.看資料庫伺服器是否啟動,資料庫是否附加上去
② asp如何對資料庫進行驗證賬號密碼是否正確
建立兩個 Session(),一個名稱為 Adminuser,一個名稱為Adminlevel,
Session("Adminuser") '在驗證成功後,存入管理賬戶的用戶名
Session("Adminlevel") '在驗證成功後,存入管理賬戶的管理許可權級別,如果需要的話
建立一個CkAdmin.asp
if session("Adminuser")="" then
response.Redirect("index.asp") '或者使用login.asp 登錄頁
end if
只要驗證不成功,就返回到首頁
Login.asp
<%
Session("Adminuser")=""
Session("Adminlevel")=""
%>
校驗登錄
set rs=server.CreateObject("adodb.recordset")
sql="select * from admin where user_name='" & user_name & "' and user_pass='" & user_pass & "'"
con.open sql,1,3
if not (rs.bof and rs.eof) then '登錄成功
Session("Adminuser")=rs("user_name")
Session("Adminlevel")=rs("Adminlevel") '如果有這個欄位
response.Redirect("Manage_index.asp") '驗證成功後,跳轉到需要的頁面
else
'這里就是驗證失敗啦.'
response.Redirect("index.asp") '或者使用login.asp 登錄頁
end if
rs.close
rs=nothing
最後,,在每個需要驗證是否管理員登錄的頁面前邊..
<!--#INCLUDE FILE="./CkAdmin.asp"--> '注意文件路徑,使用相對路徑.'
③ 在VB裡面如何驗證經過MD5加密的資料庫密碼
在網上找一段VB的 MD5 的編碼類,假設類名為 Encode,編碼函數:MD5(),資料庫路徑為: c:\test.mdb ,表名為 user ,欄位用戶名,密碼: username,password,代碼如下:
Dim nConn as object
Dim nRs as Object
Dim md5instance as new Encode
Dim SQL As String
set nConn=CreateObject("ADODB.Connection")
set nRs=CreateObject("ADODB.Recordset")
nConn.Open "Driver={Microsoft Access Driver (*.mdb)};UID=;PWD=;DBQ=c:\test.mdb"
SQL="select * from user where username=admin and password=" & md5instance.MD5("123456") '123456 是密碼
nRs.Open SQL,nConn,3,3
if nRs.Eof then
msgbox "驗證失敗!"
else
msgbox "驗證通協!"
end if
MD5 演算法請參考:
http://www.mx68.com/wangluoanquan/2006-03-29/wangluoanquan_79429.shtml
④ 用資料庫怎樣驗證賬號和密碼
你要首先連庫,要確定連上了!然後再用SQL語句選擇,就可以了,你要先選擇用戶
分別用兩個變數來保存選擇的結果
select
name
from
user
where
user.username='textFiled1.text'
這個驗證這個賬戶存不存在
然後用戶存在的時候再驗證密碼:
既然樓主可以做出界面的話,相信樓主可以寫好這個代碼咯,樓主加油吧
⑤ 易語言做的登陸器怎樣利用資料庫驗證密碼是否正確
.版本 2
.支持庫 iext
.如果真 (編輯框1.內容 = 「」 且 編輯框2.內容 = 「」)
信息框 (「請輸入登錄名,密碼!」, 0, )
返回 ()
.如果真結束
跳到 (1) ' 從資料庫首開始
.判斷開始 (查找 (讀 (「登錄名」) = 編輯框1.內容)) ' 查找賬號是否存在
.判斷開始 (讀 (「密碼」) = 編輯框2.內容) ' 查找密碼是否有誤
信息框 (「登錄成功!管理員」 + 「(」 + 編輯框1.內容 + 「)」, 0 + 64, )
登錄名 = 窗口1.編輯框1.內容
.默認
信息框 (「密碼錯誤!請重新輸入!」, #錯誤圖標, )
.判斷結束
.默認
信息框 (「沒有該用戶名」, #錯誤圖標, )
⑥ C#Access資料庫密碼賬號驗證問題
建個DBHelper類用於資料庫的連接:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Windows.Forms;
namespaceLoad
{
classDBHelper
{
privatestaticSqlCommandcmd=null;
privatestaticSqlDataReaderdr=null;
publicintRowCount{get;privateset;}
SqlConnectionsqlCnn=newSqlConnection();
SqlCommandsqlCmd=newSqlCommand();
//資料庫連接字元串
="Server=127.0.0.1;Database=dianzi;IntegratedSecurity=SSPI";
//資料庫連接Connection對象
=newSqlConnection(connectionString);
publicDBHelper()
{}
#region返回結果集
(stringsql)
{
try
{
cmd=newSqlCommand();
cmd.CommandText=sql;
cmd.Connection=connection;
cmd.Connection.Open();
dr=cmd.ExecuteReader();
returndr;
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
returnnull;
}
finally
{
//dr.Close();
//cmd.Connection.Close();
}
}
#endregion
#region對Select語句,返回int型結果集
publicstaticintGetSqlResult(stringsql)
{
try
{
cmd=newSqlCommand();
cmd.CommandText=sql;
cmd.Connection=connection;
cmd.Connection.Open();
inta=(int)cmd.ExecuteScalar();
returna;
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
return-1;
}
finally
{
cmd.Connection.Close();
}
}
#endregion
#region對Update,Insert和Delete語句,返回該命令所影響的行數
publicstaticintGetDsqlResult(stringsql)
{
try
{
cmd=newSqlCommand();
cmd.CommandText=sql;
cmd.Connection=connection;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
return1;
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message);
return-1;
}
finally
{
cmd.Connection.Close();
}
}
#endregion
}
}
Load窗體中的函數:
1、#region驗證用戶的輸入,成功返回true,失敗返回false
privateboolIsValidataInput()
{
if(txtbox1.Text.Trim()=="")
{
MessageBox.Show("請輸入用戶名!","登陸提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
txtbox1.Focus();
returnfalse;
}
elseif(txtbox2.Text=="")
{
MessageBox.Show("請輸入密碼!","登陸提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
txtbox2.Focus();
returnfalse;
}
returntrue;
}
#endregion
2、#region驗證用戶是否合法
//傳遞用戶賬號、密碼、登陸類型,合法返回true,不合法返回false
//message參數用來記錄驗證失敗的原因
privateboolIsValidataUser(stringUserName,stringUserrPwd,refstringmessage)
{
stringsql=String.Format("selectcount(*)fromUserwhereUserName='{0}'andUserPwd='{1}'",UserName,UserPwd);
inta=DBHelper.GetSqlResult(sql);
if(a<1)
{
message="該用戶名不存在或密碼錯誤;並檢查用戶類型是否選擇正確!";
returnfalse;
}
else
{
returntrue;
}
}
#endregion
3、按鈕事件
privatevoidbutton_Click(objectsender,EventArgse)
{
//標識是否為合法用戶
boolisValidUser=false;
stringmessage="登陸失敗!";
if(IsValidataInput())
{
//驗證用戶是否為合法用戶
isValidUser=IsValidataUser(txtbox1.Text.Trim(),txtbox2.Text,refmessage);
if(isValidUser)
{
Managerma=newManager();//Manager為你登陸後要顯示的窗體
ma.Show();
this.Hide();
}
else
{
MessageBox.Show(message,"登陸提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
}
}
⑦ asp.net(c#)如何讀取資料庫中數據來驗證登陸的用戶和密碼是否正確
代碼如下:
stringuname=this.txtUsername.Text;//得到登陸帳號
stringpwd=this.txtPassword.Text;//得到登陸密碼
SqlConnectionsqlCon=newSqlConnection();//創建資料庫連接對象
//初始化該對象的連接字串
sqlCon.ConnectionString
ConfigurationManager.ConnectionStrings["strConn"].ConnectionString;
sqlCon.Open();//打開資料庫連接
SqlCommandsqlComGet=newSqlCommand();//創建SqlCommand對象
sqlComGet.Connection=sqlCon;//用sqlCon初始化SqlCommand對象
sqlComGet.CommandText="select*fromTUserwhereUserName='"+uname+"'andUserPwd='"+pwd+"'";
SqlDataReadersqlDr=sqlComGet.ExecuteReader();//創建SqlDataReader對象
if(sqlDr.Read())//帳號和密碼正確
{Session["UserID"]=sqlDr["UserID"];
Session["UserEmail"]=sqlDr["UserEmail"];
Session["UserName"]=uname;//用Session記錄帳號
Session["UserPwd"]=pwd;//用Session記錄密碼
Response.Redirect("Default.aspx");
}
else//帳號或密碼錯誤
{
this.lblResults.Text="您輸入的用戶名或密碼不正確!";
}
sqlCon.Close();
⑧ C#輸入賬號密碼與資料庫驗證
stringconstr="server=.;database=Graation;uid=123;pwd=123;";//連接字元串里包含了資料庫信息
SqlConnectionconn=newSqlConnection(constr);//創建資料庫連接
conn.Open();//打開連接
//SqlDataAdaptersda=newSqlDataAdapter();//SqlDataAdapter是數據適配器,是資料庫和調用者之間的橋梁
SqlCommandcmd=newSqlCommand();//SqlCommand表示對資料庫要執行的操作命令。
cmd.CommandText="select*fromLogin";//cmd要執行的sql操作語句
cmd.Connection=conn;//cmd對應的連接
SqlDataReaderreader=cmd.ExecuteReader();
while(reader.Read())
{
stringusername=reader["Name"].ToString();
stringpassword=reader["password"].ToString();
//Trim()表示把字元串前後的空格都去除。不然有空格會干擾判斷。
if(this.textBox1.Text.Trim()==username.Trim()&&password.Trim()==this.textBox2.Text.Trim())
{
Form1f=newForm1();
f.Show();//彈出Form1這個窗體
}
else
{
MessageBox.Show("用戶名或密碼錯誤,請重新輸入");
this.textBox2.Text="";
this.textBox1.Text="";
}
⑨ 資料庫 ENCRYPT()加密的密碼怎麼驗證登錄
String.Format("selectencryptbycert(cert_id('c1'),'')fromtest,TextBox2.Text);這個是把你加密後的密碼作為欄位名來查詢了吧。另外你這邏輯有很大問題呀,就算把上面的SQL改好也不行。你的邏輯是首先判斷用戶是否存在,然後判斷密碼是否存在,你都不判斷用戶名對應的密碼是否是你輸入,只是判斷資料庫里是否存在這個密碼……