Nazhand Zareei

Nazhand Zareei

  • NA
  • 18
  • 116.5k

User authentication

Apr 18 2013 8:03 PM
I have a Log in form which connect to database to check username and password, in this User table I have a roleID which is FK from Role table (RoleID, Name, Description)

In C# Windows form application, I would like to check if it is "Admin" then show some text box on different form,

How can I implement code for this.

Thank you.

Answers (1)

2
Riddhi Valecha

Riddhi Valecha

  • 438
  • 3.3k
  • 417k
Apr 19 2013 12:27 AM
Hi....
I am giving the logic. It will work.
Do the following steps.
--------
1)On LoginPage, fire the query  - "select * from Table_Users where Username='"+txtbox1.text.tostring()+"' AND Password='"+txtbox2.text.tostring()+"'";

2)Login is successful, then fire the query -"select RoleID from Table_Users where Username='"+txtbox1.text.tostring()+"'";

3)If you are using Datareader, you can use the statement - int roleid=convert.toint32(dr["RoleID"].Tostring());

4) Now lastly fire the query - "select Role from Table_Role where ID='"+roleid+"'";

5)Here you will get the role of the user.

6)Put the conditions. i.e. if(role=="Admin") {// code here.}
------------
Do let me know if you need any other help regarding this.

Accepted Answer