我通过创建用户名和密码区域来设置管理员登录,该区域使管理员可以访问典型用户看不到的表单。
假设有 4 人正在使用此应用程序,我想让 4 人中只有 3 人可以以管理员身份登录。
我该怎么做呢 ?
这就是我创建登录功能的方式。
在我的应用程序的设置区域中,我创建了两个名称DBUsername
并将DBPassword
它们的范围设置为User
PasswordField
并且NameField
是文本框,这是登录区域的照片及其背后的代码。该功能完美运行。
不注意User Login
按钮
Public Class login
Private Property username As String = ""
Private Property password As String = ""
Dim Setting As New My.MySettings
Private Sub AdminLoginButton_Click(sender As Object, e As EventArgs) Handles AdminLoginButton.Click
If NameField.Text = "" And PasswordField.Text = "" Then
Label3.Text = "PLEASE ENTER A USERNAME AND PASSWORD"
End If
If NameField.Text = "" And PasswordField.Text.Length > 0 Then
Label3.Text = "PLEASE ENTER A NAME"
End If
If PasswordField.Text = "" And NameField.Text.Length > 0 Then
Label3.Text = "PLEASE ENTER A PASSWORD"
End If
'generage first password
If Setting.DBpassword = "" Then
'save password here
password = PasswordField.Text
Setting.DBpassword = password
Setting.Save()
Else
End If
'generate first username
If Setting.DBUsername = "" Then
username = NameField.Text
Setting.DBUsername = username
Setting.Save()
Else
End If
'check if correct name and password are entered
If PasswordField.Text = Setting.DBpassword And NameField.Text = Setting.DBUsername Then
Label3.Text = ("WELCOME " & NameField.Text)
Dim itm As Control
Me.Close()
For Each itm In MLGMain.Controls
itm.Enabled = True
Next
End If
If NameField.Text.Length >= 1 And NameField.Text <> Setting.DBUsername And PasswordField.Text.Length >= 1 And NameField.Text <> Setting.DBpassword Then
Label3.Text = "INCORRECT USERNAME AND PASSWORD COMBINATION"
NameField.Clear()
PasswordField.Clear()
End If
End Sub
结束类