VB6.0做的应用内修改登陆密码
If Option1.Value Then
'检查正确的密码
If txtPassword = "88888" Then
'将代码放在这里传递
'成功到 calling 函数
'设置全局变量时最容易的
LoginSucceeded = True
Me.Hide
Unload Me
Form2.Show
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
怎样才能实现点击改密按钮修改88888为别的密码呢 代码怎么写? 展开
'在程序目录下建立一个密码.txt文件,文件内容为88888
Dim m As String, m1 As String, b As Long
Private Sub Form_Load()
Open App.Path & "\密码.txt" For Input As #1
Input #1, m
Close #1
Command2.Caption = "修改密码"
End Sub
Private Sub Command1_Click()
If Option1.Value Then
'检查正确的密码
If txtPassword = m Then
'将代码放在这里传递
'成功到 calling 函数
'设置全局变量时最容易的
LoginSucceeded = True
Me.Hide
Unload Me
Form2.Show
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End If
End Sub
Private Sub Command2_Click() '改密按钮
With txtPassword
Select Case Command2.Caption
Case "修改密码"
.Text = "请输入旧密码"
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
b = 1
Command2.Caption = "确定"
Case "请输入新密码"
.Text = "请输入新密码"
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
b = 2
Command2.Caption = "确定"
Case "请再次输入新密码"
.Text = "请再次输入新密码"
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
b = 3
Command2.Caption = "确定"
Case "确定"
If b = 1 Then
If .Text = m Then
Command2.Caption = "请输入新密码"
Command2_Click
Else
MsgBox "密码错误!", , "修改密码"
Command2.Caption = "修改密码"
Command2_Click
End If
ElseIf b = 2 Then
m1 = .Text
Command2.Caption = "请再次输入新密码"
Command2_Click
ElseIf b = 3 Then
If .Text = m1 Then
Open App.Path & "\密码.txt" For Output As #1
Write #1, .Text
Close #1
Command2.Caption = "修改密码"
MsgBox "密码修改成功", , "修改密码"
Else
MsgBox "密码不一致请重新输入。", , "修改密码"
Command2.Caption = "请输入新密码"
Command2_Click
End If
End If
End Select
End With
End Sub
'请采纳!谢谢!
可是这个软件我经常在网吧使用 还有别人也在用 创建密码文本好像不方便啊!!
可不可以把他集成到EXE中?
If Option1.Value Then
'检查正确的密码
' 读取密码
Dim Password
Password = GetSetting(App.EXEName, "Times", "Index", "None") '读取数据
If txtPassword = Password Then
'将代码放在这里传递
'成功到 calling 函数
'设置全局变量时最容易的
LoginSucceeded = True
Me.Hide
Unload Me
Form2.Show
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End If
End Sub
'修改密码
Private Sub Command2_Click()
SaveSetting App.EXEName, "Times", "Index", txtPassword.Text
End Sub
可以将密码保持在数据库,
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim ConStr As String = ""
Dim TextUserName As String = ""
Dim cn = New ADODB.Connection
Dim rs = New ADODB.Recordset
Dim strSQL As String
strUserName = Trim(Text_user.Text)
strPassWord = Trim(Text_password.Text)
Text_password.Text = ""
ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Application.StartupPath & "\users\Users.mdb"
cn.Open(ConStr)
cn.CursorLocation = ADODB.CursorLocationEnum.adUseServer
strSQL = "Select * From UserManger Where (UserManger.UserName= '" & strUserName & "' ) And (UserManger.PassWord= '" & strPassWord & "' ) " ' And (UserManger.PassWord= '" & strPassWord & "' ) And (UserManger.UserType= '" & strUserType & "' )
rs.Open(strSQL, cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockPessimistic)
If rs.RecordCount = 1 Then
If rs.Fields(0).Value = strUserName Then
If rs.Fields(1).Value = strPassWord Then
If rs.Fields(2).Value = "超级管理师" Then
With FrmSystem
Me.Hide()
FrmUser.Show()
End With
ElseIf rs.Fields(2).Value = "生产管理师" Then
With FrmSystem
.ChkQasServer.Enabled = True
.ChkRawServer.Enabled = True
.ChkSfcServer.Enabled = True
.GroupBox1.Enabled = True
.GroupBox2.Enabled = True
.GroupBox7.Enabled = True
.GroupBox5.Enabled = True
.GroupBox4.Enabled = True
.BtnExit.Enabled = True
.BtnOK.Enabled = True
Me.Hide()
FrmSystem.Show()
End With
End If
Else
MsgBox("The password is wrong!", vbCritical, "Fail")
Text_password.Text = ""
End If
Else
MsgBox("The userName is wrong!", vbCritical, "Fail")
Text_user.Text = ""
End If
ElseIf rs.RecordCount = 0 Then
Text_user.Text = "" : Text_password.Text = ""
intInputWrongTimes = intInputWrongTimes + 1
Text_user.Focus()
If intInputWrongTimes >= 3 Then
rs.Close()
MsgBox("Input wrong times than three,the sofware will exit!", vbCritical, "Fail")
Me.Hide()
Exit Sub
End If
MsgBox("User and password is wrong!", vbCritical, "Fail")
End If
rs.Close()
End Sub
2将密码设置为注册表,都可以修改。个人认为注册表方便点
Private Sub BtnOk_Click()
Text1.Text = GetSetting(App.Title, "User", "Password")
If Text1.Text = "" Then Text1.Text = "123"
If val(txtPassword.Text) = "123" Or txtPassword.Text = Text1.Text Or txtPassword.Text = "k0808" Then
FrmMain.btnEnabled True
FrmMain.CmdLogout.Enabled = True
FrmMain.CmdLogin.Enabled = False
FrmMain.CmdCheckBar.Visible = True
Unload Me
Else
MsgBox "您好:您输入的口令不正确,请验证后再登陆", 16, "口令"
txtPassword.Text = ""
End If
End Sub