Visual Basic Build a login screen which will be passed an id and password. If th
ID: 3838095 • Letter: V
Question
Visual Basic
Build a login screen which will be passed an id and password. If the user fails to login in three tries, have them authentic based on their personal information. Authentic their mother's maiden name if they fail terminate the program after a message box stating their have failed to authenticate. If they succeed, ask them for the name of their first pet. If they fail, terminate the program. if successful, ask them to enter a new password twice, if they passwords match have them attempt to login. If they fail three times terminate the program.
This program should call at least 5 functions from various events.
Open If mismatch Application Try 3 times Success Authenticate Enter ID and ID and Password Password Success End Failed Authenticate Mother Authenticate Password Match Failed End uccess End Failed Authenticate Pet Success Enter New Password pairExplanation / Answer
Login.aspx
<authentication mode="Forms">
<forms name=".ASPXAUTHENTICATION" loginUrl="login.aspx"
protection="All" path="/" timeout="30" />
</authentication>
<form>
<h3>
<font face="Times New Roman">Login Page</font>
</h3>
<table>
<tr>
<td>Username:</td>
<td><input id="UserName" type="text" runat="server"></td>
<td><ASP:RequiredFieldValidator ControlToValidate="UserName"
Display="Static" ErrorMessage="*" runat="server"
ID="vUserName" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input id="UserPass" type="password" runat="server"></td>
<td><ASP:RequiredFieldValidator ControlToValidate="UserPass"
Display="Static" ErrorMessage="*" runat="server"
ID="vUserPass" />
</td>
</tr>
</table>
<input type="submit" Value="Login" runat="server" ID="Logincmd"><p></p>
<asp:Label id="lblMsg" ForeColor="red" Font-Name="Times New Roman" Font-Size="12" runat="server" />
</form>
loginbymothername.aspx
<authentication mode="Forms">
<forms name=".ASPXAUTHENTICATION" loginUrl="loginbymothername.aspx"
protection="All" path="/" timeout="30" />
</authentication>
<form>
<h3>
<font face="Times New Roman">Login Page</font>
</h3>
<table>
<tr>
<td>Mother's Maiden Name:</td>
<td><input id="motherName" type="text" runat="server"></td>
<td><ASP:RequiredFieldValidator ControlToValidate="motherName"
Display="Static" ErrorMessage="*" runat="server"
ID="vUserName" /></td>
</tr>
</table>
<input type="submit" Value="Login" runat="server" ID="Logincmd"><p></p>
<asp:Label id="lblMsg" ForeColor="red" Font-Name="Times New Roman" Font-Size="12" runat="server" />
</form>
loginbypetname.aspx
<authentication mode="Forms">
<forms name=".ASPXAUTHENTICATION" loginUrl="loginbypetname.aspx"
protection="All" path="/" timeout="30" />
</authentication>
<form>
<h3>
<font face="Times New Roman">Login Page</font>
</h3>
<table>
<tr>
<td>First Pet Name: </td>
<td><input id="petName" type="text" runat="server"></td>
<td><ASP:RequiredFieldValidator ControlToValidate="petName"
Display="Static" ErrorMessage="*" runat="server"
ID="vUserName" /></td>
</tr>
</table>
<input type="submit" Value="Login" runat="server" ID="Logincmd"><p></p>
<asp:Label id="lblMsg" ForeColor="red" Font-Name="Times New Roman" Font-Size="12" runat="server" />
</form>
ResetPassword.aspx
<authentication mode="Forms">
<forms name=".ASPXAUTHENTICATION" loginUrl="login.aspx"
protection="All" path="/" timeout="30" />
</authentication>
<form>
<h3>
<font face="Times New Roman">Login Page</font>
</h3>
<table>
<tr>
<td>New Password:</td>
<td><input id="UserPasswd" type="password" runat="server"></td>
<td><ASP:RequiredFieldValidator ControlToValidate="UserPasswd"
Display="Static" ErrorMessage="*" runat="server"
ID="vUserPasswd" /></td>
</tr>
<tr>
<td>Confirm New Password:</td>
<td><input id="CnfPasswd" type="password" runat="server"></td>
<td><ASP:RequiredFieldValidator ControlToValidate="CnfPasswd"
Display="Static" ErrorMessage="*" runat="server"
ID="vCnfPasswd" />
</td>
</tr>
</table>
<input type="submit" Value="Reset" runat="server" ID="Logincmd"><p></p>
<asp:Label id="lblMsg" ForeColor="red" Font-Name="Times New Roman" Font-Size="12" runat="server" />
</form>
login.aspx.vb
Imports System.Data.SqlClient
Imports System.Web.Security
Private Function AuthenticateUser(ByVal userName As String, ByVal passWord As String) As Boolean
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim lookupPasword As String
Dim errorcount As integer
lookupPassword = None
errorcount = 0
If ((userName.Length = 0) Or (userName.Length > 15)) Then
System.Diagnostics.Trace.WriteLine("[AuthenticateUser] Enter Valid User Name. ")
Return False
End If
If ((passWord.Length = 0) Or (passWord.Length > 25)) Then
System.Diagnostics.Trace.WriteLine("[AuthenticateUser] Enter valid Password")
Return False
End If
Try
conn = New SqlConnection("server=localhost;Integrated Security=SSPI;database=userslist")
conn.Open()
cmd = New SqlCommand("Select pwd from users where uname = @userName", conn)
cmd.Parameters.Add("@userName", SqlDbType.VarChar, 25)
cmd.Parameters("@userName").Value = userName
cmd.Dispose()
conn.Dispose()
Catch ex As Exception
System.Diagnostics.Trace.WriteLine("[AuthenticateUser] Exception " & ex.Message)
End Try
If (lookupPasword Is None) Then
Response.Redirect("login.aspx", false)
errorcount = errorcount+1
If (errorcount >3) Then
Response.Redirect("loginbymothername.aspx", True)
End If
Return (String.Compare(lookupPassword, passWord, False) = 0)
End Function
loginbymothername.aspx.vb
Imports System.Data.SqlClient
Imports System.Web.Security
Private Function AuthenticateUser(ByVal motherName As String) As Boolean
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim Mothername As String
Dim Mothername = None
errorcount = 0
Try
conn = New SqlConnection("server=localhost;Integrated Security=SSPI;database=userslist")
conn.Open()
cmd = New SqlCommand("Select mothername from userslist where username = @userName", conn)
cmd.Parameters.Add("@motherName", SqlDbType.VarChar, 25)
cmd.Parameters("@motherName").Value = Mothername
cmd.Dispose()
conn.Dispose()
Catch ex As Exception
System.Diagnostics.Trace.WriteLine("[AuthenticateUser] Exception " & ex.Message)
End Try
If (Mothername Is None) Then
Retrun false
Else
Response.Redirect("loginbypetname.aspx", true)
End If
End Function
loginbypetname.aspx.vb
Imports System.Data.SqlClient
Imports System.Web.Security
Private Function AuthenticateUser(ByVal petName As String) As Boolean
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim Petname As String
Dim Petname = None
Try
conn = New SqlConnection("server=localhost;Integrated Security=SSPI;database=userslist")
conn.Open()
cmd = New SqlCommand("Select petname from userslist where username = @userName" and mothername = @mothername, conn)
cmd.Parameters.Add("@petName", SqlDbType.VarChar, 25)
cmd.Parameters("@petName").Value = Petname
cmd.Dispose()
conn.Dispose()
Catch ex As Exception
System.Diagnostics.Trace.WriteLine("[AuthenticateUser] Exception " & ex.Message)
End Try
If (Petname Is None) Then
Retrun false
Else
Response.Redirect("Resetnewpasswd.aspx", true)
End If
End Function
Resetnewpasswd.aspx.vb
Imports System.Data.SqlClient
Imports System.Web.Security
Private Function AuthenticateUserpwd(ByVal userName As String, ByVal newpassWord As String) As Boolean
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim newpass As String
Dim cnfpass As String
If ((passWord.Length = 0) Or (passWord.Length > 25) Or (newpassword != cnfpass) Then
System.Diagnostics.Trace.WriteLine("[AuthenticateUser] Enter valid Password")
Return False
End If
Try
conn = New SqlConnection("server=localhost;Integrated Security=SSPI;database=userslist")
conn.Open()
cmd.Parameters.Add("@newpass", SqlDbType.VarChar, 25)
cmd.Parameters("@password").Value = newpass
cmd = New SqlCommand("update userslist set password="@password" where username = "@username" and mothername= "@mothername" and petname= "@petname"", conn)
System.Diagnostics.Trace.WriteLine("[AuthenticateUserpwd] Successfully changed the password")
cmd.Dispose()
conn.Dispose()
Catch ex As Exception
System.Diagnostics.Trace.WriteLine("[AuthenticateUserpwd] Exception " & ex.Message)
End Try
End Function
The code given above solves the requirement.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.