Click here to Skip to main content
12,634,101 members (26,480 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
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 5-Feb-13 9:36am
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
CShubham 6-Feb-13 1:27am
   
Hi!! Kindly find this article
http://www.dotnetfunda.com/articles/article979-aspnet-authentication-and-authorization.aspx
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

try this

The below code should be in your Loging page.
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
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
  Permalink  
Comments
Marcus Kramer 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100