用vb做了一個登陸程式,改密碼的時候應該怎樣改?如圖
在用戶名密碼與原資料相同的情況下才能改,改的時候應該輸入怎樣的陳述句?
uj5u.com熱心網友回復:
就是這個。。。。。。uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
這個應該不難,不過你的圖沒有,也不知道你的登錄資料存盤在哪里,因此對應你的問題不好回答,做一個用Access資料庫存盤的例子,供你參考:(資料庫名稱 ”AA.mdb“,資料表名稱” 登錄表“。在【工程】-【參考】中添加二個參考:
下面是全部代碼:
Dim db As New ADODB.Connection, RS As New ADODB.Recordset, PPID As Long, YMM As String
Private Sub Combo1_Click()
Text1.Text = "": Text2.Text = "": Text3.Text = "": Text4.Text = ""
PPID = 0: YMM = ""
Call KKK(db)
RS.Open "select * from 登錄表 Where 用戶名='" & Combo1.Text & "'", db, 2, 2
Text1.Text = RS!用戶名
PPID = RS!ID
YMM = RS!密碼
RS.Close
db.Close
End Sub
Private Sub Command1_Click()
If PPID = 0 Then
MsgBox "你沒有選擇修改密碼的用戶!"
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "你沒有輸入用戶原來的密碼!"
Exit Sub
End If
If YMM <> Text2.Text Then
MsgBox "你輸入的原密碼不正確!"
Exit Sub
End If
If Text3.Text = "" Then
MsgBox "你沒有輸入用戶新的密碼!"
Exit Sub
End If
If Text4.Text = "" Then
MsgBox "你沒有再次輸入用戶新的密碼!"
Exit Sub
End If
If Text3.Text <> Text4.Text Then
MsgBox "二次輸入的新密碼不對,請檢查!"
Exit Sub
End If
'下面開始修改密碼了
Call KKK(db)
RS.Open "select * from 登錄表 Where ID=" & PPID & " And 用戶名='" & Text1.Text & "' And 密碼='" & Text2.Text & "' ", db, 2, 2
RS!密碼 = Text3.Text
RS.Update
RS.Close
db.Close
MsgBox "這個用戶的密碼已經修改成功!"
Unload Me
Form1.Show
End Sub
Private Sub Form_Load()
Combo1.Clear
Call KKK(db)
RS.Open "select * from 登錄表", db, 2, 2
Do While Not RS.EOF
Combo1.AddItem RS!用戶名
RS.MoveNext
Loop
RS.Close
db.Close
Text1.Text = "": Text2.Text = "": Text3.Text = "": Text4.Text = ""
PPID = 0: YMM = ""
End Sub
Private Sub KKK(db)
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AA.mdb;Persist Security Info=False" '
End Sub
下面是程式界面:

uj5u.com熱心網友回復:
樓上是個好老師。uj5u.com熱心網友回復:
RS.Open "select * from 登錄表 Where ID=" & PPID & " And 用戶名='" & Text1.Text & "' And 密碼='" & Text2.Text & "' "太容易被攻擊了。
攻擊者只需選任意一個用戶,原密碼欄中填寫 "' OR '1' = '1”,再填寫新密碼。
此時,SQL 字串就是:
"select * from 登錄表 Where ID=xxx And 用戶名='yyy' And 密碼='' OR '1' = '1'"
密碼就被改了。
應
RS.Open "select * from 登錄表 Where ID=" & PPID & " And 用戶名='" & Text1.Text & "'
然后再檢測密碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/76803.html
上一篇:用vb讀出dat檔案第二列的最小值,這個最小值接下來我會用到。。謝謝
下一篇:求大神,老師讓我們把時間控制元件洗掉,或者只用一個,讓我們實作相同的功能。。溫度監控的功能。剛接觸VB,總是達不到效果。
