Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a VBA script that simulates validation of user-passwords. The script shou

ID: 3801367 • Letter: C

Question

Create a VBA script that simulates validation of user-passwords.

The script should:

- prompt users for a password.

- length of the password entered is at least 8 characters.

- first character of the password is an UpperCase letter.

- password contains at least one of the numbers 3, 7, 8, or 9.

- prompt for passwords until the user enters a valid password or the user makes 5 unsuccessful attempts.

Display a warning message if there are 5 attempts, otherwise Display a string that consists of the length of the password concatenated with the password.

Explanation / Answer

Please find only the required function here.

Private Sub cmdSubmit1_Click()
Dim Username As String
Username = txtUserNameIn.Text
Dim password As String
password = txtPasswordIn.Text
'Check to see if data is entered into field: txtUserNameIn
If IsNull(Me.txtUserNameIn) Or Me.txtUserNameIn = "" Then
MsgBox "You must enter your username.", vbOKOnly, "Required Data"
Me.txtUserNameIn.SetFocus
Exit Sub
End If

'Check to see if data is entered into field: txtPasswordIn
If IsNull(Me.txtPasswordIn) Or Me.txtPasswordIn = "" Then
MsgBox "You must enter your Password (case sensitive).", vbOKOnly, "Required Data"
Me.txtPasswordIn.SetFocus
Exit Sub
End If

'Check to see if the Username & Password entered is a valid username in the 'User Register'
'****************
Dim temp As String
On Error Resume Next
temp = WorksheetFunction.VLookup(Me.txtUserNameIn.Value, Range("UserRegister"), 1, 0)

If Username = temp Then
'****************
Err.Clear
temp = ""
temp = WorksheetFunction.VLookup(Me.txtUserNameIn.Value, Range("UserRegister"), 2, 0)
On Error Goto 0
If password = temp Then
Sheets("ADMIN").Visible = xlSheetVisible
MsgBox "Password & Username Accepted"
Unload Me
Sheets("ADMIN").Select
Range("A1").Select
Else
Sheets("ADMIN").Visible = xlVeryHidden
MsgBox "Username & Password Combination Not Accepted, Workbook will close"
Unload Me
'ThisWorkbook.Close (I'm not wanting to go-live with this bit yet, so commented out)
End If
End If


End Sub