执行操作入下:
输入原密码,查询是否正确,不正确提示,否则输入新密码,确认密码,两者对比是否相同,相同则将密码设置为新密码,退出系统重新登陆,否则提示两者不同,无法修改。
使用数据库表:
user_info(存放用户信息)
具体代码如下:
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim a As VbMsgBoxResult
'对User_Info表操作
Dim mrcuser As ADODB.Recordset '用于存放记录集
Dim userSQL As String '用于存放SQL语句
Dim userMsgText As String '用于存放返回信息
'输入旧密码判断是否为空,是否正确
If Trim(txtOldPassWord.Text) = "" Then
MsgBox "请输入原始密码", vbOKCancel + vbQuestion, "提示"
Else
userSQL = "select * from user_info where userID='" & Trim(frmLogin.txtUserName) & "'"
Set mrcuser = ExecuteSQL(userSQL, userMsgText)
'判断原密码是否正确
If txtOldPassWord = Trim(mrcuser.Fields(1)) Then
'判断修改的密码是否与原密码一致
If txtNewPassWord.Text = Trim(txtOldPassWord.Text) Then
MsgBox "修改密码与原密码一致,无须修改!", vbOKCancel + vbQuestion, "提示"
txtOldPassWord = ""
txtNewPassWord = ""
txtDetermine = ""
mrcuser.Close
Else
If txtNewPassWord.Text <> Trim(txtDetermine.Text) Then
MsgBox "确认密码和新密码不一致,请重新输入!", vbOKCancel + vbQuestion, "提示"
Else
mrcuser.Fields(1) = Trim(txtNewPassWord.Text)
mrcuser.Update
mrcuser.Close
a = MsgBox("密码已修改完毕,是否重新登录?", vbOKCancel + vbQuestion, "提示")
If a = vbOK Then
Unload Me
Unload frmMain
frmLogin.Show
End If
End If
End If
Else
MsgBox "原密码不正确,请重新输入!", vbOKCancel + vbQuestion, "提示"
txtOldPassWord = ""
txtNewPassWord = ""
txtDetermine = ""
mrcuser.Close
End If
End If
End Sub
优化方面:
1.不可粘贴
Private Sub txtDetermine_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'禁止粘贴
If Button = 2 Then
Clipboard.Clear
End If
End Sub
2.限制字符类型
https://blog.csdn.net/TGB__15__ZYB/article/details/86636625
3.背景图随窗体改变而改变
Dim H As Single '定义窗体高的变量
Dim W As Single '定义窗体高的变量
Private Sub Form_Load()
H = Me.Height
W = Me.Width
Me.PaintPicture Me.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight '实现背景图随窗体变大而改变 '背景图随窗体改变
End Sub
Private Sub Form_Resize()
Me.Height = H
Me.Width = W
End Sub