Click here to Skip to main content
15,895,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim _objStudentInfo As StudentInfo = New StudentInfo(Txtuserid.Text, Txtpassword.Text)
       Session("objStudentInfo") = _objStudentInfo
       Dim con As SqlConnection
       con = New SqlConnection("server=***;user id=sa;password=***;database=***")
       con.Open()
       Dim cmd As SqlCommand
       Dim rdr As SqlDataReader
       cmd = New SqlCommand("select USRMST_USERLOGID,USRMST_PASS from [SYSTEM].[SYSTEM_USER_LOGIN] where USRMST_USERLOGID='" + Txtuserid.Text + "' And USRMST_PASS='" + Txtpassword.Text + "'", con)
       rdr = cmd.ExecuteReader()
       While rdr.Read()
           If rdr("USRMST_USERLOGID").ToString() = Txtuserid.Text AndAlso rdr("USRMST_PASS").ToString() = Txtpassword.Text Then
               SingleSessionPreparation.CreateAndStoreSessionToken(Txtuserid.Text)
               Dim sKey As String = Txtuserid.Text + Txtpassword.Text
               Dim sUser As String = Convert.ToString(Cache(sKey))
               If sUser Is Nothing OrElse sUser = [String].Empty Then
                   Dim i = HttpContext.Current.User
                   Dim SessTimeOut As New TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0)
                   HttpContext.Current.Cache.Insert(sKey, sKey, Nothing, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.Normal, Nothing)

                   Dim context As HttpContext = HttpContext.Current
                   Dim page As Page = TryCast(context.Handler, Page)
                   HttpContext.Current.User.Identity.Name.Contains(sKey)
                   page.Session("user") = HttpContext.Current.Session.SessionID
                   ''Session("user") = Txtuserid.Text + Txtpassword.Text

                   ' Let them in - redirect to main page, etc.
                   Response.Redirect("Home.aspx?Uid=" + Txtuserid.Text + "")
               Else
                   ' cache item exists, so too bad...
                   lblDisplay.Text = "<Marquee><h1><font color=red>Already Logged IN</font></h1></marquee>"
                   Return
               End If

               lblDisplay.Text = "Invalid UserName and Password Try Again !!!"
           End If
       End While


What I have tried:

using this way i Restricted user.
But i am not able to remove user after log of, he tell me your all ready login
Posted
Comments
F-ES Sitecore 29-Nov-17 4:45am    
This isn't really possible.

https://forums.asp.net/post/5825784.aspx
Dotnet_Dotnet 29-Nov-17 10:29am    
sir
youshouldclearthession
HttpContext.Session.Abandon();
Sinisa Hajnal 30-Nov-17 6:05am    
You should put your connection string into configuration file and encrypt it.
Furthermore, you should NEVER EVER concatenate user input into your SQL. Use prepared statements or stored procedures (SQL Injection)
Imagine entering username (without square brackets): ['; DROP TABLE USRMST_USERLOGID; --]
manoj s sherje 30-Nov-17 6:39am    
Thanks for your comment but this my sample code my practice is work with web.config and stored procedures.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900