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
Home » Applications » Access » Login – password encrypt

Login – password encrypt

February 7, 2011 - Posted in Access, Applications, ASP.NET

Login.aspx [ form page ]

Login.asp.vb [code behind]

Imports System.IO

Imports System.Data.OleDb

Imports System.Web.UI.WebControls.ImageButton

Imports System.Web.UI.WebControls.TextBox

Imports System.Web.SessionState

Imports System.Web.Security

Imports System.Web

Partial Class Control_Panel

Inherits System.Web.UI.Page

Protected Sub Login_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Login.Click

‘/ defining controls

Dim usn As TextBox

Dim pwd As TextBox

‘/ binding controls

usn = Login.FindControl(“usn”)

pwd = Login.FindControl(“pwd”)

Dim user As String

Dim key As String

user = usn.Text.ToString()

key = pwd.Text.ToString()


‘/ password encryption [SHA1]

Dim sha1Obj As New System.Security.Cryptography.SHA1CryptoServiceProvider

Dim bytesToHash() As Byte= System.Text.Encoding.ASCII.GetBytes(key)

bytesToHash = sha1Obj.ComputeHash(bytesToHash)

Dim keyCode As String = “”

For Each b As Byte In bytesToHash

keyCode += b.ToString(“x2”)

Next

‘/ access db connection – MS Access 2007/10 driver * you can define your own sql connection

Dim ConnDB As New OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;DataSource=” & Server.MapPath(“my_user.accdb”))

Dim cmd As New OleDbCommand(“SELECT * FROM users WHERE (usn = ‘” &usn.Text.ToString() & “‘) AND (pwd = ‘” & keyCode & “‘);”,ConnDB)

Dim reader As OleDbDataReader

Try

‘/ open connection

cmd.Connection.Open()

reader = cmd.ExecuteReader()

If reader.Read() Then

LabelUSN.Text = “<font color=’green’>Login successful!</font> – <a href=’Control-Panel.aspx?do=1′>Enter</a> secure pages”

Session(“Name”) = reader(1).ToString()

Else

Label2.Text = (“<font color=’red’>Login failed</font>”)

End If

‘/ close connection

cmd.Connection.Close()

Catch ex As Exception

Label2.Text = “<font color=’red’>Error:</font> “ & ex.Message.ToString()

End Try

End Sub

End Class

Tags: Access, ASP.NET, Encryption, Login

« Disable back button
Count number of rows in gridview »
  • Posts by Date

    February 2011
    M T W T F S S
     123456
    78910111213
    14151617181920
    21222324252627
    28  
    « Jan   Mar »
  • 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