Iowa Web Network

Just another WordPress site
  • Home
  • ASP.NET
  • Classic ASP
  • CSS
  • Contact
  • .NET 4.0
  • Applications
    • Access
    • ASP.NET
      • Controls
      • Date and Time Format
      • Email
      • Survey Form
      • Validation Controls
      • VS2010
    • Encryption
    • jQuery
    • System Info
  • Articles
  • Classic ASP
  • Classified
  • Css
  • Error
    • application error
    • application pool
    • system error
  • HTML
  • Images
  • JavaScript
  • MS SQL
  • Networking
    • Wi-Fi
  • SQL
  • UNC
  • VS2012

Login

December 27, 2010 - Posted in Access, Applications, ASP.NET - Permalink

~ 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.Security

Partial Class Login
Inherits System.Web.UI.Page

Protected 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 If

cmd.Connection.Close()

‘/ end
Catch ex As Exception
Label2.Text = “ERROR: ” & ex.Message.ToString() ‘/ in case of error

End Try

End Sub

End Class

Login

December 27, 2010 - Posted in Applications, ASP.NET - Permalink

~ Access db backend ~

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.Security

Partial Class Login
Inherits System.Web.UI.Page

Protected 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”)

‘/ 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 = ” & pwd.Text.ToString() & “);”, ConnDB)
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()
Response.Redirect(“MySecurePage.aspx”)
Else
Label1.Text = (“<font color=’red’>Wrong Username or Password!</font>”)
End If

cmd.Connection.Close()

‘/ end
Catch ex As Exception
Label2.Text = “ERROR: ” & ex.Message.ToString()     ‘/ in case of error

End Try

End Sub

End Class

Login

December 27, 2010 - Posted in Applications, ASP.NET - Permalink

~ Simple login application ~

Web.config

<system.web>

<authentication mode=”Forms”>

<forms loginUrl=”~/ Login.aspx” timeout=”2880″/>

</authentication>

</system.web>

Login.aspx

<asp:Label ID=”UserNameLabel” runat=”server” AssociatedControlID=”UserName”>User Name:</asp:Label>

<asp:TextBox ID=”UserName” runat=”server”></asp:TextBox>

<asp:RequiredFieldValidator ID=”UserNameRequired” runat=”server”
ControlToValidate=”UserName” ErrorMessage=”User Name is required.”
ToolTip=”User Name is required.” ValidationGroup=”Login1″>*
</asp:RequiredFieldValidator>

<asp:Label ID=”PasswordLabel” runat=”server” AssociatedControlID=”Password”>Password:</asp:Label>

<asp:TextBox ID=”Password” runat=”server” TextMode=”Password”></asp:TextBox>

<asp:RequiredFieldValidator ID=”PasswordRequired” runat=”server”
ControlToValidate=”Password” ErrorMessage=”Password is required.”
ToolTip=”Password is required.” ValidationGroup=”Login1″>*</asp:RequiredFieldValidator>

<asp:Literal ID=”FailureText” runat=”server” EnableViewState=”False”></asp:Literal>

<asp:Button ID=”LoginButton” runat=”server” CommandName=”Login” Text=”Log In” ValidationGroup=”Login1″ />

Login.aspx.vb

Partial Class Login
Inherits System.Web.UI.Page

Function SiteSpecificAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean
‘ Insert code that implements a site-specific custom
‘ authentication method here.
If UserName = “YourUsn” And Password = “YourPwd” Then
Response.Redirect(“YourPage.aspx”)
End If
‘ This example implementation always returns false.
Return False
End Function

Sub OnAuthenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
Dim Authenticated As Boolean
Authenticated = SiteSpecificAuthenticationMethod(Login1.UserName, Login1.Password)

e.Authenticated = Authenticated
End Sub

End Class

« Older Entries
Newer Entries »
  • Posts by Date

    June 2026
    M T W T F S S
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  
    « Oct    
  • Recent Posts

    • ASP.NET (C#) – Session Info – Count Clicks
    • ASP.NET (VB) File Upload with Delete
    • ASP.NET (VB) – Multiple Files Upload
    • VB.NET – User Impersonation
    • VB.NET – OleDbConnection Properties
  • Admin Corner

    Login
    Email
  • Post Tags

    Access array ASP.NET bulleted button Calendar characters Classic ASP Colorbox Container.DataItem content Controls Count CSS Date datepicker Email Encryption file Format Form Validation Gridview HTML image Javascript jQuery list Login monitor OleDbConnection Parameters Programming Record update redirect security select session SQL Time total upload uptime Visual Studio web design website

Iowa Web Network is proudly powered by WordPress