Guest User

Untitled

a guest
Mar 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. Imports System.Security
  2. Imports System.Security.Principal
  3. Imports System.Web.Security
  4.  
  5. Public Class login
  6. Inherits System.Web.UI.Page
  7.  
  8. Protected UserName As TextBox
  9. Protected Password As TextBox
  10. Protected Message As Label
  11.  
  12. #Region " Web Form Designer Generated Code "
  13.  
  14. 'This call is required by the Web Form Designer.
  15. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  16.  
  17. End Sub
  18.  
  19. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  20. 'CODEGEN: This method call is required by the Web Form Designer
  21. 'Do not modify it using the code editor.
  22. InitializeComponent()
  23. End Sub
  24.  
  25. #End Region
  26.  
  27. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  28. 'Put user code to initialize the page here
  29. End Sub
  30.  
  31. Sub ValidLogin(ByVal Obj As Object, ByVal e As EventArgs)
  32.  
  33. ' Only attempt a login if all form fields on the page are valid
  34. If Page.IsValid = True Then
  35.  
  36. Dim encryptedPassword As String
  37.  
  38. ' EncryptPassword
  39. Dim EncryptManager As iTab.PasswordEncrypt = New iTab.PasswordEncrypt()
  40. encryptedPassword = EncryptManager.ComputeMD5Hash(Password.Text)
  41.  
  42. Response.Write(encryptedPassword)
  43.  
  44. ' Attempt to Validate User Credentials using EmployeeStart
  45. Dim LoginManager As iTab.LoginManager = New iTab.LoginManager()
  46. Dim employeeId As Int32 = LoginManager.Login(UserName.Text, encryptedPassword)
  47.  
  48. Response.Write("id:" & employeeId)
  49. Response.Write("<br>")
  50. Response.Write("user: " & User.Identity.Name)
  51.  
  52. Dim RoleList() As String
  53.  
  54. If employeeId <> 0 Then
  55.  
  56. 'Response.Write("okay")
  57. 'Response.End()
  58.  
  59. ' Lookup the employee details
  60. Dim employeeDetails As iTab.EmployeeDetails = LoginManager.GetEmployeeDetails(employeeId)
  61.  
  62. 'Response.Write(employeeDetails.FullName)
  63. 'Response.End()
  64.  
  65. ' Store the user's fullname in a cookie for personalization purposes
  66. Response.Cookies("FullName").Value = employeeDetails.FullName
  67. Response.Cookies("Email").Value = employeeDetails.Email
  68. Response.Cookies("employeeID").Value = employeeId
  69. Response.Cookies("employeeGUID").Value = employeeDetails.employeeGUID
  70.  
  71.  
  72. If Request.Cookies("ATRoles") Is Nothing Then
  73.  
  74. RoleList = LoginManager.GetEmployeeSecurity(employeeId)
  75.  
  76. ' Create a string to persist the roles
  77. Dim RoleListString As String = ""
  78. Dim role As String
  79.  
  80. For Each role In RoleList
  81.  
  82. RoleListString += role
  83. RoleListString += ";"
  84.  
  85. Next role
  86.  
  87. Response.Write("RoleList: " & RoleListString & "<br><br>")
  88.  
  89. ' Create a cookie authentication ticket.
  90. ' version
  91. ' user name
  92. ' issue time
  93. ' expires every hour
  94. ' don't persist cookie
  95. ' roles
  96. Dim ticket As New FormsAuthenticationTicket(1, Context.User.Identity.Name, DateTime.Now, DateTime.Now.AddHours(1), False, RoleListString)
  97.  
  98. ' Encrypt the ticket
  99. Dim cookieStr As String = FormsAuthentication.Encrypt(ticket)
  100.  
  101. Response.Write("cookieString: " & cookieStr & "<br><br>")
  102.  
  103. ' Send the cookie to the client
  104. Response.Cookies("ATRoles").Value = cookieStr
  105. Response.Cookies("ATRoles").Path = "/"
  106. Response.Cookies("ATRoles").Expires = DateTime.Now.AddMinutes(1)
  107. Else
  108.  
  109. ' Get roles from roles cookie
  110. Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(Context.Request.Cookies("ATRoles").Value)
  111.  
  112. 'convert the string representation of the role data into a string array
  113. Dim userRoles As New ArrayList()
  114.  
  115. Dim role As String
  116.  
  117. For Each role In ticket.UserData.Split(New Char() {";"c})
  118. userRoles.Add(role)
  119. Response.Write("Role: " & role & "<br>")
  120. Next role
  121.  
  122. RoleList = CType(userRoles.ToArray(GetType(String)), String())
  123.  
  124. End If
  125.  
  126. Response.Write("context: " & context.User.Identity.Name)
  127.  
  128.  
  129. ' Add our own custom principal to the request containing the roles in the auth ticket
  130. Context.User = New GenericPrincipal(Context.User.Identity, RoleList)
  131.  
  132. Response.End()
  133.  
  134. ' Redirect browser back to originating page
  135. FormsAuthentication.RedirectFromLoginPage(employeeId, False)
  136.  
  137. Else
  138. Response.Write("Login Failed")
  139. Response.End()
  140. Message.Text = "&#183 Name or password incorrect. Login failed.<br><br>"
  141. End If
  142.  
  143. End If
  144.  
  145. End Sub
  146.  
  147. End Class
Add Comment
Please, Sign In to add comment