Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. Imports System.Web
  2. Imports System.Web.Services
  3. Imports System.Web.Services.Protocols
  4. Imports System.Data.SqlClient
  5. Imports System.Data
  6. Imports System.Text
  7. Imports System.Security.Cryptography
  8.  
  9. Partial Class login
  10. Inherits System.Web.UI.Page
  11.  
  12. Public strCon As String = "Data Source=TOSHIBA-PC\SQLExpress;Initial Catalog=Project_iMage;Integrated Security=True;"
  13. Public oSqlConnection As SqlConnection = New SqlConnection(strCon)
  14. Public oSqlCommand As New SqlCommand
  15. Public strSql As String
  16.  
  17. Public Sub setKoneksi()
  18. oSqlConnection = New SqlConnection("Data Source=TOSHIBA-PC\SQLExpress;Initial Catalog=Project_iMage;Integrated Security=True;")
  19. End Sub
  20.  
  21. Function GetSecureVal(ByVal param As String) As String
  22. If param = "" Then
  23. GetSecureVal = param
  24. Exit Function
  25. End If
  26.  
  27. If IsNumeric(param) Then
  28. GetSecureVal = CLng(param)
  29. Else
  30. GetSecureVal = Replace(CStr(param), "'", "''")
  31. End If
  32. End Function
  33.  
  34. Public Function GenerateHash(ByVal SourceText As String) As String
  35. 'Create an encoding object to ensure the encoding standard for the source text
  36. Dim Ue As New UnicodeEncoding()
  37. 'Retrieve a byte array based on the source text
  38. Dim ByteSourceText() As Byte = Ue.GetBytes(SourceText)
  39. 'Instantiate an MD5 Provider object
  40. Dim Md5 As New MD5CryptoServiceProvider()
  41. 'Compute the hash value from the source
  42. Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
  43. 'And convert it to String format for return
  44. Return Convert.ToBase64String(ByteHash)
  45. End Function
  46.  
  47. Public Function cekLogin(ByVal username As String, ByVal password As String) As Boolean
  48. Me.strSql = "select * from userImage where username = '" + GetSecureVal(username) + "' and password = '" + GetSecureVal(GenerateHash(password)) + "'"
  49. Me.oSqlCommand = New SqlCommand(Me.strSql, Me.oSqlConnection)
  50. Dim oSqlDataReader As SqlDataReader
  51. Me.oSqlConnection.Open()
  52. oSqlDataReader = Me.oSqlCommand.ExecuteReader
  53. If oSqlDataReader.HasRows Then
  54. oSqlDataReader.Close()
  55. oSqlCommand.Dispose()
  56. oSqlConnection.Close()
  57. Return True
  58. Else
  59. oSqlDataReader.Close()
  60. oSqlCommand.Dispose()
  61. oSqlConnection.Close()
  62. Return False
  63. End If
  64. End Function
  65.  
  66.  
  67. Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
  68. Dim username As String = txtloginuser.Text
  69. Dim password As String = txtloginpassword.Text
  70. Dim bisalogin As Boolean
  71.  
  72. bisalogin = cekLogin(username, password)
  73. If bisalogin = True Then
  74. If username = "admin1m4ge" Then
  75. Session("usr") = "admin"
  76. Response.Redirect("allprofile.aspx")
  77. Else
  78. Session("usr") = username
  79. Response.Redirect("profile.aspx")
  80. End If
  81.  
  82. Else
  83. lblvalidpassuss.Text = "Username and password didn't match"
  84. End If
  85. End Sub
  86.  
  87. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  88. setKoneksi()
  89. End Sub
  90.  
  91. Protected Sub txtloginuser_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtloginuser.TextChanged
  92. If txtloginuser.Text = "" Then
  93. txtloginuser.Text = "Username"
  94. End If
  95. End Sub
  96. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement