Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Security
- Imports System.Security.Principal
- Imports System.Web.Security
- Public Class login
- Inherits System.Web.UI.Page
- Protected UserName As TextBox
- Protected Password As TextBox
- Protected Message As Label
- #Region " Web Form Designer Generated Code "
- 'This call is required by the Web Form Designer.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- End Sub
- Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
- 'CODEGEN: This method call is required by the Web Form Designer
- 'Do not modify it using the code editor.
- InitializeComponent()
- End Sub
- #End Region
- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'Put user code to initialize the page here
- End Sub
- Sub ValidLogin(ByVal Obj As Object, ByVal e As EventArgs)
- ' Only attempt a login if all form fields on the page are valid
- If Page.IsValid = True Then
- Dim encryptedPassword As String
- ' EncryptPassword
- Dim EncryptManager As iTab.PasswordEncrypt = New iTab.PasswordEncrypt()
- encryptedPassword = EncryptManager.ComputeMD5Hash(Password.Text)
- Response.Write(encryptedPassword)
- ' Attempt to Validate User Credentials using EmployeeStart
- Dim LoginManager As iTab.LoginManager = New iTab.LoginManager()
- Dim employeeId As Int32 = LoginManager.Login(UserName.Text, encryptedPassword)
- Response.Write("id:" & employeeId)
- Response.Write("<br>")
- Response.Write("user: " & User.Identity.Name)
- Dim RoleList() As String
- If employeeId <> 0 Then
- 'Response.Write("okay")
- 'Response.End()
- ' Lookup the employee details
- Dim employeeDetails As iTab.EmployeeDetails = LoginManager.GetEmployeeDetails(employeeId)
- 'Response.Write(employeeDetails.FullName)
- 'Response.End()
- ' Store the user's fullname in a cookie for personalization purposes
- Response.Cookies("FullName").Value = employeeDetails.FullName
- Response.Cookies("Email").Value = employeeDetails.Email
- Response.Cookies("employeeID").Value = employeeId
- Response.Cookies("employeeGUID").Value = employeeDetails.employeeGUID
- If Request.Cookies("ATRoles") Is Nothing Then
- RoleList = LoginManager.GetEmployeeSecurity(employeeId)
- ' Create a string to persist the roles
- Dim RoleListString As String = ""
- Dim role As String
- For Each role In RoleList
- RoleListString += role
- RoleListString += ";"
- Next role
- Response.Write("RoleList: " & RoleListString & "<br><br>")
- ' Create a cookie authentication ticket.
- ' version
- ' user name
- ' issue time
- ' expires every hour
- ' don't persist cookie
- ' roles
- Dim ticket As New FormsAuthenticationTicket(1, Context.User.Identity.Name, DateTime.Now, DateTime.Now.AddHours(1), False, RoleListString)
- ' Encrypt the ticket
- Dim cookieStr As String = FormsAuthentication.Encrypt(ticket)
- Response.Write("cookieString: " & cookieStr & "<br><br>")
- ' Send the cookie to the client
- Response.Cookies("ATRoles").Value = cookieStr
- Response.Cookies("ATRoles").Path = "/"
- Response.Cookies("ATRoles").Expires = DateTime.Now.AddMinutes(1)
- Else
- ' Get roles from roles cookie
- Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(Context.Request.Cookies("ATRoles").Value)
- 'convert the string representation of the role data into a string array
- Dim userRoles As New ArrayList()
- Dim role As String
- For Each role In ticket.UserData.Split(New Char() {";"c})
- userRoles.Add(role)
- Response.Write("Role: " & role & "<br>")
- Next role
- RoleList = CType(userRoles.ToArray(GetType(String)), String())
- End If
- Response.Write("context: " & context.User.Identity.Name)
- ' Add our own custom principal to the request containing the roles in the auth ticket
- Context.User = New GenericPrincipal(Context.User.Identity, RoleList)
- Response.End()
- ' Redirect browser back to originating page
- FormsAuthentication.RedirectFromLoginPage(employeeId, False)
- Else
- Response.Write("Login Failed")
- Response.End()
- Message.Text = "· Name or password incorrect. Login failed.<br><br>"
- End If
- End If
- End Sub
- End Class
Add Comment
Please, Sign In to add comment