VB密码读取
因本人初学VB,现寻求好心的高手给偶写一个VB程序的密码登陆界面读取源程序,如:怎么样把用户名和密码存储到某个文件中,登陆的时候又怎样读取。这样的VB源程序,谢谢!本人将...
因本人初学VB,现寻求好心的高手给偶写一个VB程序的密码登陆界面读取源程序,如:怎么样把用户名和密码存储到某个文件中,登陆的时候又怎样读取。这样的VB源程序,谢谢!本人将对有效的帮助者追加100分!
*****************************************
山山红叶飞,你好!首先感谢你的热心帮助,但我不知道你这个密码是放在哪?又如何更改密码、如何删除用户?
谢谢 展开
*****************************************
山山红叶飞,你好!首先感谢你的热心帮助,但我不知道你这个密码是放在哪?又如何更改密码、如何删除用户?
谢谢 展开
3个回答
展开全部
加密和解密一直都是相对立的,你能加密,别人就能解密,再有就是跟踪你的程序运行来分析。所以,用户名和密码写入文件是没有问题的(当然写入注册表更有隐蔽性,因为一般人可以根据写入文件的先后来找到你的写入内容);如果你可以被多用户允许使用,那么别人更改一下你设置中的用户名,或者修改分析后的密码,那么加密设置就是形同虚设。
建议:
1、采用复杂计算,将用户名和密码内容采用多次运算,合在一起,形成一个定长的验证串,然后写入注册表,做为对照依据。
2、程序运行需要判断登录时,将用户输入的用户名合密码再次运算,和保存的验证串对比,存在即通过。
3、下面的程序仅供参考,你可以进行更全面的完善,算法可以设计得更复杂(反正计算起来时很快的)。
窗体中添加一些标签,注明相关输入说明;添加5个文本框:Text1、Text2、Text3,分别表示添加用户的用户名、密码以及密码确认;添加Text4、Text5,表示登录的用户名和密码;添加Command1,表示“添加用户”的命令按钮;添加Command2,表示登录的“确定”按钮。代码如下:
Option Explicit
Dim NameLength As Integer, MmLength As Integer, Number As Integer
Dim I As Long, J As Long, K As Integer, S As String, T As String
Dim Nam(1 To 16) As Integer, Mima(1 To 16) As Integer, Result(1 To 16) As String
Dim Succeed As Boolean
Private Sub Command1_Click()
NameLength = Len(Text1)
If NameLength < 6 Or NameLength > 16 Then Label1 = "用户名长度错误": Exit Sub
'用户名长度是6~16个ASCII字符或者3~8个汉字
If Text2 <> Text3 Then Label1 = "两次密码不相同": Exit Sub
MmLength = Len(Text2)
If MmLength < 6 Or MmLength > 16 Then Label1 = "密码长度错误": Exit Sub
'密码长度是6~16个ASCII字符
For I = 1 To NameLength
J = Asc(UCase(Mid(Text1, I, 1)))
If J < 48 Or (J > 57 And J < 65) Or J > 90 Then Label1 = "用户名包含非法字符": Exit Sub
'判断用户名是否由数字或字母组成的,对于是否允许汉字,可再加入判断
Next
For I = 1 To MmLength
J = Asc((Mid(Text2, I, 1)))
If J < 32 Or J > 127 Then Label1 = "密码包含非法字符": Exit Sub
'判断密码是否合法(可显示ASCII码)
Next
S = Text1 & Space(16 - NameLength)
T = Text2 & Space(16 - MmLength)
K = 0 '进位标志
For I = 1 To 16
Nam(I) = Asc(Mid(S, I, 1)) + ((I + 3) ^ 5 Mod 123)
Mima(I) = Asc(Mid(T, I, 1)) + ((I + 5) ^ 3 Mod 119)
J = ((Nam(I) Xor Mima(I) Xor (I * 3 + 67))) * 128 * 32 + K
'循环移位
K = J \ 256
Result(I) = Chr(J Mod 95 + 32)
'对用户名和密码进行加密处理,方法可以再完善,越复杂越好
Next
S = Join(Result, "")
Number = Val(GetSetting("MiMa", "Data", "Number")) + 1
SaveSetting "MiMa", "Data", "D" & Number, Join(Result, "")
SaveSetting "MiMa", "Data", "Number", Number
Label1 = "用户添加成功,目前共有" & Number & "个用户"
End Sub
Private Sub Command2_Click()
'密码验证
NameLength = Len(Text4)
MmLength = Len(Text5)
S = Text4 & Space(16 - NameLength)
T = Text5 & Space(16 - MmLength)
K = 0 '进位标志
For I = 1 To 16
Nam(I) = Asc(Mid(S, I, 1)) + ((I + 3) ^ 5 Mod 123)
Mima(I) = Asc(Mid(T, I, 1)) + ((I + 5) ^ 3 Mod 119)
J = ((Nam(I) Xor Mima(I) Xor (I * 3 + 67))) * 128 * 32 + K
K = J \ 256
Result(I) = Chr(J Mod 95 + 32)
'对用户名和密码进行加密计算,方法与添加用户时相同
Next
S = Join(Result, "")
Number = Val(GetSetting("MiMa", "Data", "Number"))
For I = 1 To Number
T = GetSetting("MiMa", "Data", "D" & I)
If S = T Then Succeed = True: Label1 = "登录成功": Exit Sub
'设置登录成功标志,转入正常运行
Next
Label1 = "用户名或密码错误,登录失败"
End Sub
Private Sub Form_Load()
Succeed = False
'登录成功与否的标志
End Sub
建议:
1、采用复杂计算,将用户名和密码内容采用多次运算,合在一起,形成一个定长的验证串,然后写入注册表,做为对照依据。
2、程序运行需要判断登录时,将用户输入的用户名合密码再次运算,和保存的验证串对比,存在即通过。
3、下面的程序仅供参考,你可以进行更全面的完善,算法可以设计得更复杂(反正计算起来时很快的)。
窗体中添加一些标签,注明相关输入说明;添加5个文本框:Text1、Text2、Text3,分别表示添加用户的用户名、密码以及密码确认;添加Text4、Text5,表示登录的用户名和密码;添加Command1,表示“添加用户”的命令按钮;添加Command2,表示登录的“确定”按钮。代码如下:
Option Explicit
Dim NameLength As Integer, MmLength As Integer, Number As Integer
Dim I As Long, J As Long, K As Integer, S As String, T As String
Dim Nam(1 To 16) As Integer, Mima(1 To 16) As Integer, Result(1 To 16) As String
Dim Succeed As Boolean
Private Sub Command1_Click()
NameLength = Len(Text1)
If NameLength < 6 Or NameLength > 16 Then Label1 = "用户名长度错误": Exit Sub
'用户名长度是6~16个ASCII字符或者3~8个汉字
If Text2 <> Text3 Then Label1 = "两次密码不相同": Exit Sub
MmLength = Len(Text2)
If MmLength < 6 Or MmLength > 16 Then Label1 = "密码长度错误": Exit Sub
'密码长度是6~16个ASCII字符
For I = 1 To NameLength
J = Asc(UCase(Mid(Text1, I, 1)))
If J < 48 Or (J > 57 And J < 65) Or J > 90 Then Label1 = "用户名包含非法字符": Exit Sub
'判断用户名是否由数字或字母组成的,对于是否允许汉字,可再加入判断
Next
For I = 1 To MmLength
J = Asc((Mid(Text2, I, 1)))
If J < 32 Or J > 127 Then Label1 = "密码包含非法字符": Exit Sub
'判断密码是否合法(可显示ASCII码)
Next
S = Text1 & Space(16 - NameLength)
T = Text2 & Space(16 - MmLength)
K = 0 '进位标志
For I = 1 To 16
Nam(I) = Asc(Mid(S, I, 1)) + ((I + 3) ^ 5 Mod 123)
Mima(I) = Asc(Mid(T, I, 1)) + ((I + 5) ^ 3 Mod 119)
J = ((Nam(I) Xor Mima(I) Xor (I * 3 + 67))) * 128 * 32 + K
'循环移位
K = J \ 256
Result(I) = Chr(J Mod 95 + 32)
'对用户名和密码进行加密处理,方法可以再完善,越复杂越好
Next
S = Join(Result, "")
Number = Val(GetSetting("MiMa", "Data", "Number")) + 1
SaveSetting "MiMa", "Data", "D" & Number, Join(Result, "")
SaveSetting "MiMa", "Data", "Number", Number
Label1 = "用户添加成功,目前共有" & Number & "个用户"
End Sub
Private Sub Command2_Click()
'密码验证
NameLength = Len(Text4)
MmLength = Len(Text5)
S = Text4 & Space(16 - NameLength)
T = Text5 & Space(16 - MmLength)
K = 0 '进位标志
For I = 1 To 16
Nam(I) = Asc(Mid(S, I, 1)) + ((I + 3) ^ 5 Mod 123)
Mima(I) = Asc(Mid(T, I, 1)) + ((I + 5) ^ 3 Mod 119)
J = ((Nam(I) Xor Mima(I) Xor (I * 3 + 67))) * 128 * 32 + K
K = J \ 256
Result(I) = Chr(J Mod 95 + 32)
'对用户名和密码进行加密计算,方法与添加用户时相同
Next
S = Join(Result, "")
Number = Val(GetSetting("MiMa", "Data", "Number"))
For I = 1 To Number
T = GetSetting("MiMa", "Data", "D" & I)
If S = T Then Succeed = True: Label1 = "登录成功": Exit Sub
'设置登录成功标志,转入正常运行
Next
Label1 = "用户名或密码错误,登录失败"
End Sub
Private Sub Form_Load()
Succeed = False
'登录成功与否的标志
End Sub
展开全部
你实现学习一下VB和ACCESS数据库的连接,问题就十分简单了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上方法可以,以下给出使用文本文件保存用户名及密码并经VB6.0调试的代码,供参考:
Option Explicit
Dim userName As String
Dim password As String
Dim LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
userName = txtUserName
password = txtPassword
Open "C:\Windows\System\no1.TXT" For Output As #1
Print #1, userName, password
Close
Unload Me
End Sub
Private Sub cmdOK_Click()
'检查正确的密码
If txtPassword = password And txtUserName = userName Then
LoginSucceeded = True
'将代码放在这里传递
Else
MsgBox "无效的用户名或密码,请重试!", , "登录"
txtUserName.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Private Sub Form_Load()
On Error GoTo uerror
Open "C:\Windows\System\no1.TXT" For Input As #1
Input #1, userName, password
Close
Exit Sub
uerror:
End Sub
Private Sub Form_Unload(Cancel As Integer)
userName = txtUserName
password = txtPassword
Open "C:\Windows\System\no1" For Output As #1
Write #1, userName, password
Close
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmdOk.SetFocus
End If
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtPassword.SetFocus
End If
End Sub
Option Explicit
Dim userName As String
Dim password As String
Dim LoginSucceeded As Boolean
Private Sub cmdCancel_Click()
userName = txtUserName
password = txtPassword
Open "C:\Windows\System\no1.TXT" For Output As #1
Print #1, userName, password
Close
Unload Me
End Sub
Private Sub cmdOK_Click()
'检查正确的密码
If txtPassword = password And txtUserName = userName Then
LoginSucceeded = True
'将代码放在这里传递
Else
MsgBox "无效的用户名或密码,请重试!", , "登录"
txtUserName.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Private Sub Form_Load()
On Error GoTo uerror
Open "C:\Windows\System\no1.TXT" For Input As #1
Input #1, userName, password
Close
Exit Sub
uerror:
End Sub
Private Sub Form_Unload(Cancel As Integer)
userName = txtUserName
password = txtPassword
Open "C:\Windows\System\no1" For Output As #1
Write #1, userName, password
Close
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmdOk.SetFocus
End If
End Sub
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtPassword.SetFocus
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询