~ Access db backend & SHA1 or MD5 encryption ~
Web.config
<system.web>
<authentication mode=”Forms”>
<forms loginUrl=”Login.aspx” timeout=”2880″/>
</authentication></system.web>
Login.aspx
<form id=”form1″ runat=”server” >
<table >
<tr>
<td colspan=”2″><b>Login Form</b></td>
</tr>
<tr>
<td>Intranet Username: </td><td style=”color: Red;” >
<asp:TextBox ID=”usn” runat=”server” TextMode=”password” />
<asp:RequiredFieldValidator ID=”ReqVal_1″ controltovalidate=”usn”
validationgroup=”Login1″ runat=”server” ErrorMessage=” ? ” >
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Teller #: </td><td style=”color: Red;” ><asp:TextBox ID=”pwd” runat=”server” TextMode=”password” />
<asp:RequiredFieldValidator ID=”ReqVal_2″ controltovalidate=”pwd”
validationgroup=”Login1″ runat=”server” ErrorMessage=” ? ” >
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator runat=”server” ErrorMessage=”Numbers only.”
ControlToValidate=”pwd” validationgroup=”Login1″ ValidationExpression=”^\d+$” /></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td></td>
<td ><asp:Label ID=”Label1″ runat=”server” /><br />
<asp:Label ID=”Label2″ runat=”server” /></td>
</tr>
<tr>
<td></td><td ><asp:Button ID=”submit” runat=”server” Text=”submit”
CausesValitdation=”True” ValidationGroup=”Login1″ /></td>
</tr>
</table>
</form>
Loginn.aspx.vb
Imports System.IO
Imports System.Data.OleDb
Imports System.Web.UI.WebControls.Button
Imports System.Web.UI.WebControls.TextBox
Imports System.Web.SessionState
Imports System.Web.SecurityPartial Class Login
Inherits System.Web.UI.PageProtected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
‘defining variables/controls
Dim usn As TextBox
Dim pwd As TextBox‘binding controls
usn = submit.FindControl(“usn”)
pwd = submit.FindControl(“pwd”)‘/ here are 2 encryption methods
‘********************************’
Dim key As String
Dim key1 As String
key = FormsAuthentication.HashPasswordForStoringInConfigFile(“pwd”, “SHA1”) ‘/ here we implement SHA1 hash
key1 = FormsAuthentication.HashPasswordForStoringInConfigFile(“pwd”, “MD5”) ‘/ here we implement MD5 hash‘/ access db connection – MS Access 2007/10 driver * you can define your own sql connection
Dim ConnDB As New OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/myDB.mdb;Persist Security Info=True”)Dim cmd As New OleDbCommand(“SELECT * FROM Login WHERE (username = ‘” & usn.Text.ToString() & “‘) AND (password = ” & key.Text.ToString() & “);”, ConnDB)
‘/ simple replace “key” with “key1” to use MD5 encryption method
Dim reader As OleDbDataReader
Try
‘/ open connection
cmd.Connection.Open()
reader = cmd.ExecuteReader()
If reader.Read() Then
Label1.Text = (“<font color=’green’>You are logged in!</font>”)
Session(“Name”) = reader(1).ToString() ‘/ write session “Name” so you can greet user after successful login
Response.Redirect(“MySecurePage.aspx”)
Else
Label1.Text = (“<font color=’red’>Wrong Username or Password!</font>”)
End Ifcmd.Connection.Close()
‘/ end
Catch ex As Exception
Label2.Text = “ERROR: ” & ex.Message.ToString() ‘/ in case of errorEnd Try
End Sub
End Class