Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Web
- Imports System.Web.Services
- Imports System.Web.Services.Protocols
- Imports System.Data.SqlClient
- Imports System.Data
- Imports System.Text
- Imports System.Security.Cryptography
- Partial Class login
- Inherits System.Web.UI.Page
- Public strCon As String = "Data Source=TOSHIBA-PC\SQLExpress;Initial Catalog=Project_iMage;Integrated Security=True;"
- Public oSqlConnection As SqlConnection = New SqlConnection(strCon)
- Public oSqlCommand As New SqlCommand
- Public strSql As String
- Public Sub setKoneksi()
- oSqlConnection = New SqlConnection("Data Source=TOSHIBA-PC\SQLExpress;Initial Catalog=Project_iMage;Integrated Security=True;")
- End Sub
- Function GetSecureVal(ByVal param As String) As String
- If param = "" Then
- GetSecureVal = param
- Exit Function
- End If
- If IsNumeric(param) Then
- GetSecureVal = CLng(param)
- Else
- GetSecureVal = Replace(CStr(param), "'", "''")
- End If
- End Function
- Public Function GenerateHash(ByVal SourceText As String) As String
- 'Create an encoding object to ensure the encoding standard for the source text
- Dim Ue As New UnicodeEncoding()
- 'Retrieve a byte array based on the source text
- Dim ByteSourceText() As Byte = Ue.GetBytes(SourceText)
- 'Instantiate an MD5 Provider object
- Dim Md5 As New MD5CryptoServiceProvider()
- 'Compute the hash value from the source
- Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
- 'And convert it to String format for return
- Return Convert.ToBase64String(ByteHash)
- End Function
- Public Function cekLogin(ByVal username As String, ByVal password As String) As Boolean
- Me.strSql = "select * from userImage where username = '" + GetSecureVal(username) + "' and password = '" + GetSecureVal(GenerateHash(password)) + "'"
- Me.oSqlCommand = New SqlCommand(Me.strSql, Me.oSqlConnection)
- Dim oSqlDataReader As SqlDataReader
- Me.oSqlConnection.Open()
- oSqlDataReader = Me.oSqlCommand.ExecuteReader
- If oSqlDataReader.HasRows Then
- oSqlDataReader.Close()
- oSqlCommand.Dispose()
- oSqlConnection.Close()
- Return True
- Else
- oSqlDataReader.Close()
- oSqlCommand.Dispose()
- oSqlConnection.Close()
- Return False
- End If
- End Function
- Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
- Dim username As String = txtloginuser.Text
- Dim password As String = txtloginpassword.Text
- Dim bisalogin As Boolean
- bisalogin = cekLogin(username, password)
- If bisalogin = True Then
- If username = "admin1m4ge" Then
- Session("usr") = "admin"
- Response.Redirect("allprofile.aspx")
- Else
- Session("usr") = username
- Response.Redirect("profile.aspx")
- End If
- Else
- lblvalidpassuss.Text = "Username and password didn't match"
- End If
- End Sub
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- setKoneksi()
- End Sub
- Protected Sub txtloginuser_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtloginuser.TextChanged
- If txtloginuser.Text = "" Then
- txtloginuser.Text = "Username"
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement