CreateCookies()
--------------------------------------------------------------------------
Public Sub CreateCookies()
'check if remember me checkbox is checked on login
If (Me.RememberCheckbox.Checked) Then
'Check if the browser support cookies
If (Request.Browser.Cookies) Then
'Check if the cookie with name PBLOGIN exist on user's machine
If (Request.Cookies("PBLOGIN") Is Nothing) Then
'Create a cookie with expiry of 30 days
Dim uidPwd As HttpCookie = New HttpCookie("PBLOGIN")
uidPwd("UserName") = Me.email.Text
uidPwd("Pwd") = Me.password.Text
uidPwd.Expires = DateTime.Now.AddDays(5)
Response.Cookies.Add(uidPwd)
Dim x As String = Request.Cookies("PBLOGIN")("UserName").ToString()
Dim y As String = Request.Cookies("PBLOGIN")("Pwd").ToString()
'Response.Cookies("PBLOGIN").Expires = DateTime.Now.AddDays(30)
''Write username to the cookie
'Response.Cookies("PBLOGIN").Item("UNAME") = Me.email.Text
''Write password to the cookie
'Response.Cookies("PBLOGIN").Item("UPASS") = Me.password.Text
''If the cookie already exist then wirte the user name and password on the cookie
'Else
' Response.Cookies("PBLOGIN").Item("UNAME") = Me.email.Text
' Response.Cookies("PBLOGIN").Item("UPASS") = Me.password.Text
End If
End If
End If
End Sub
---------------------------------------------------------------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack() Then
CheckCookies()
End If
End Sub
-------------------------------------------------------------------------------
Public Sub CheckCookies()
'Check if the browser support cookies
If Request.Browser.Cookies Then
'Check if the cookies with name PBLOGIN exist on user's machine
If Request.Cookies("PBLOGIN") IsNot Nothing Then
'Pass the user name and password to the VerifyLogin method
Me.VerifyLogin(Request.Cookies("PBLOGIN")("UserName").ToString(), Request.Cookies("PBLOGIN")("Pwd").ToString())
End If
End If
End Sub
------------------------------------------------------------------------------------------
Protected Sub VerifyLogin(ByVal UserName As String, ByVal Password As String)
Try
Me.email.Text = UserName
Me.password.Text = Password
Catch ex As System.Exception
Response.Write(ex.Message)
End Try
End Sub
--------------------------------------------------------------------------
Public Sub CreateCookies()
'check if remember me checkbox is checked on login
If (Me.RememberCheckbox.Checked) Then
'Check if the browser support cookies
If (Request.Browser.Cookies) Then
'Check if the cookie with name PBLOGIN exist on user's machine
If (Request.Cookies("PBLOGIN") Is Nothing) Then
'Create a cookie with expiry of 30 days
Dim uidPwd As HttpCookie = New HttpCookie("PBLOGIN")
uidPwd("UserName") = Me.email.Text
uidPwd("Pwd") = Me.password.Text
uidPwd.Expires = DateTime.Now.AddDays(5)
Response.Cookies.Add(uidPwd)
Dim x As String = Request.Cookies("PBLOGIN")("UserName").ToString()
Dim y As String = Request.Cookies("PBLOGIN")("Pwd").ToString()
'Response.Cookies("PBLOGIN").Expires = DateTime.Now.AddDays(30)
''Write username to the cookie
'Response.Cookies("PBLOGIN").Item("UNAME") = Me.email.Text
''Write password to the cookie
'Response.Cookies("PBLOGIN").Item("UPASS") = Me.password.Text
''If the cookie already exist then wirte the user name and password on the cookie
'Else
' Response.Cookies("PBLOGIN").Item("UNAME") = Me.email.Text
' Response.Cookies("PBLOGIN").Item("UPASS") = Me.password.Text
End If
End If
End If
End Sub
---------------------------------------------------------------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack() Then
CheckCookies()
End If
End Sub
-------------------------------------------------------------------------------
Public Sub CheckCookies()
'Check if the browser support cookies
If Request.Browser.Cookies Then
'Check if the cookies with name PBLOGIN exist on user's machine
If Request.Cookies("PBLOGIN") IsNot Nothing Then
'Pass the user name and password to the VerifyLogin method
Me.VerifyLogin(Request.Cookies("PBLOGIN")("UserName").ToString(), Request.Cookies("PBLOGIN")("Pwd").ToString())
End If
End If
End Sub
------------------------------------------------------------------------------------------
Protected Sub VerifyLogin(ByVal UserName As String, ByVal Password As String)
Try
Me.email.Text = UserName
Me.password.Text = Password
Catch ex As System.Exception
Response.Write(ex.Message)
End Try
End Sub