Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Need help please Authentication please


I have these property username(String),password(string) ,name(String) and Role(Char) in my database(Authentication table)
i need a Authentication(login) page.as per the Role. please give me some example links.
Posted
Comments
Abhishek Pant 5-Feb-13 14:43pm    
http://www.asp.net/web-api/overview/security/authentication-and-authorization/authentication-and-authorization-in-aspnet-web-api
[no name] 6-Feb-13 1:27am    
Hi!! Kindly find this article
http://www.dotnetfunda.com/articles/article979-aspnet-authentication-and-authorization.aspx

I was working on same task and made it by reading below blog

http://www.asp.net/web-forms/tutorials/security/roles/role-based-authorization-cs[^]


Accept and vote if helps otherwise revert back with queries
--RDB
 
Share this answer
 
v3
try this

The below code should be in your Loging page.
VB
Sub validateuser()
       Try
           sqlcon = New OleDbConnection(constr)
           sqlcon.Open()
           sqlcmd = New OleDbCommand("SELECT COUNT(*) FROM att_userrole WHERE username = '" + Login1.UserName + " AND password = '" + Login1.Password + "'", sqlcon)
           retval = sqlcmd.ExecuteScalar
           If retval = 1 Then
               sqlcmd = New OleDbCommand("SELECT role, emailid FROM att_userrole WHERE username = '" + Login1.UserName + "'", sqlcon)
               sqlrdr = sqlcmd.ExecuteReader()
               sqlrdr.Read()
               Session("username") = Login1.UserName
               getrole = (sqlrdr.Item("role"))
               Session("userrole") = getrole
               getemail = (sqlrdr.Item("emailid"))
               Session("reqemailid") = getemail
               Response.Redirect("~\Home.aspx")
               'Response.Write("you are valid " & Session("username") & " with role " & getrole)
           Else
               'IF USERNAME IS INVALID
               '-----YOUR CODE GOES HERE----
              lbl_msg.Text = ("Invalid login attmept")
 
           End If
       Catch ex As Exception
           lbl_msg.Text = ex.Message.ToString
       End Try
   End Sub


After authentication and checking you save the details in Sessions. Then in other pages just check the session values like the below
VB
If Session("username") = "" Then
          loggedin = 0
          Response.Redirect("~\login.aspx")
      Else
          Master.ChangeLabel("Welcome " & Session("username") & " | " & Session("userrole") & " | ")
      End If
      If Session("userrole") = "Admin" Then
         'You are admin and put your code here
      Else
          'You are guest, put your code here

      End If
 
Share this answer
 
Comments
fjdiewornncalwe 6-Feb-13 13:56pm    
My 1. Sql Injection nightmare.
joe_j 7-Feb-13 8:08am    
didnt understand that comment!
faizyab 2009 9-Feb-13 2:22am    
Thank you so much . this example will be very helpful for me .
joe_j 10-Feb-13 6:17am    
You are welcome. If it helped, then it would be nice to vote this answer please

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