Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Remember me next time - how to use - VB.NET

Reply
Thread Tools

Remember me next time - how to use - VB.NET

 
 
viki viki is offline
Junior Member
Join Date: May 2009
Posts: 4
 
      07-10-2009
Hi

I am new to .NET and i have problem in using login control. I made a simple login page and it works fine but i dont know how to use the remember me next time option. can anyone please help me with some piece of code or links..

Thanks in Advance.
Viki
 
Reply With Quote
 
 
 
 
viki viki is offline
Junior Member
Join Date: May 2009
Posts: 4
 
      07-15-2009
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient

Partial Class login
Inherits System.Web.UI.Page

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If Not IsPostBack Then
If Request.Cookies("myCookie") IsNot Nothing Then
Dim cookie As HttpCookie = Request.Cookies.[Get]("myCookie")
Login1.UserName = cookie.Values("username")
Login1.RememberMeSet = (Not [String].IsNullOrEmpty(Login1.UserName))
End If
Dim txtUser As TextBox = TryCast(Login1.FindControl("UserName"), TextBox)
If txtUser IsNot Nothing Then
Me.SetFocus(txtUser)
End If
End If
Response.Cache.SetNoStore()

End Sub


Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
If YourValidationFunction(Login1.UserName, Login1.Password) Then
e.Authenticated = True
End If
End Sub

Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As EventArgs)
If ViewState("LoginErrors") Is Nothing Then
ViewState("LoginErrors") = 0
End If

Dim ErrorCount As Integer = CInt(ViewState("LoginErrors")) + 1
ViewState("LoginErrors") = ErrorCount

If (ErrorCount > 3) AndAlso (Login1.PasswordRecoveryUrl <> String.Empty) Then
Response.Redirect(Login1.PasswordRecoveryUrl)
End If
End Sub

Private Function YourValidationFunction(ByVal UserName As String, ByVal Password As String) As Boolean
Dim boolReturnValue As Boolean = False
Dim strConnection As String = "Data Source=SELVANOTEBOOK\MSSQLSERVER2008;Initial Catalog=AgentLoginDB;Integrated Security=SSPI;"
Dim sqlConnection As New SqlConnection(strConnection)
Dim SQLQuery As String = "SELECT username, password FROM userdatabase where username='" & UserName & "' and password = '" & Password & "'"
Session("username") = UserName
Dim command As New SqlCommand(SQLQuery, sqlConnection)
Dim Dr As SqlDataReader
sqlConnection.Open()
Dr = command.ExecuteReader()

While Dr.Read()
If (UserName = Dr("UserName").ToString()) And (Password = Dr("Password").ToString()) Then
boolReturnValue = True
End If
Dr.Close()
Return boolReturnValue
End While
Return boolReturnValue
End Function


Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn

Dim myCookie As New HttpCookie("myCookie")
Dim remember As [Boolean] = Login1.RememberMeSet

If remember Then
Dim persistDays As Int32 = 15
myCookie.Values.Add("username", Login1.UserName)
'you can add years and months too here
myCookie.Expires = DateTime.Now.AddDays(persistDays)
Else
myCookie.Values.Add("username", String.Empty)
' overwrite empty string is safest
'you can add years and months too here
myCookie.Expires = DateTime.Now.AddMinutes(5)
End If

Response.Cookies.Add(myCookie)


End Sub


End Class
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
set expire time of "remember next time" Ben ASP .Net 2 07-18-2008 08:45 AM
login control: remember me next time =?Utf-8?B?QmVuIFIu?= ASP .Net 4 05-18-2006 02:30 PM
Login control: remember me next time =?Utf-8?B?QmVuIFIu?= ASP .Net 4 05-18-2006 01:25 AM
login control: remember me next time =?Utf-8?B?QmVuIFIu?= ASP .Net 1 05-16-2006 05:48 PM



Advertisments