multiple user authentication..

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 25
Reputation: bharathi_n_r is an unknown quantity at this point 
Solved Threads: 0
bharathi_n_r bharathi_n_r is offline Offline
Light Poster

multiple user authentication..

 
0
  #1
Jan 3rd, 2008
Hi there,i have joined newly to this site....I am a learner as off now.i am developing a windows application using c#.net..
I have two types of users Admin and Normal users.
I am having one login screen.i want the application to identify the two types of users when they enter their username and password.
i saw the post of using session in asp.net,but how to initialize the session and how to use it and how to identify the two types of users who are in the same table.

The user login details for both admin and normal users are in a single table called account..
Table account
uId Pwd
(for admin) admin admin
(for normal user) counter counter
Help me out dude......
Thanks in advance......
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: multiple user authentication..

 
0
  #2
Jan 3rd, 2008
In UserClass define UserType enumerator and assign it a value (came from database userTable) indicates it as an admin or user
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: multiple user authentication..

 
0
  #3
Jan 4th, 2008
Well Dear ....... u r saying u r developing a Windows Application ........There is nothing like Session in Windows app.....Session are used in Web app.
is there any Flag....in ur user table.....???
if it has.....then u can check it in ur query.....
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: multiple user authentication..

 
0
  #4
Jan 4th, 2008
No flag needed, he must put a foreign key in UserTable to identity UserType (Admin or User)
About session, I didn't notice
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: multiple user authentication..

 
0
  #5
Jan 4th, 2008
Okay i thought.....he/she uses the single table....actually he/she writes...."The user login details for both admin and normal users are in a single table called account.."
if the user Type (admin or normal user) details are in the other table....then u must have to use the foreign key.........
thanx Ramy
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: bharathi_n_r is an unknown quantity at this point 
Solved Threads: 0
bharathi_n_r bharathi_n_r is offline Offline
Light Poster

Re: multiple user authentication..

 
0
  #6
Jan 5th, 2008
Hey fellows,
Thanks for the replies dudes...
Like ramy said the use of foreign key is necessary if i have two tables.but i am having a single table called account...

I will explain it clearly.
I have a login form where both admin and normal users enter.

The login details are in a single table called account which has the user name and password of both type of users..

If admin logs in he should be taken to a different form and if normal user logs in he should be taken to a different form..

I should do this by taking the user name..I should identify the user(super or normal) by the user name he enters in textbox1...see the code

[code] if ((textBox1.Text == "") || (textBox2.Text == ""))
{
label3.Visible = true;
label3.Text = "User name or Password is left blank";
return;
}
Con = new SqlConnection("Server=PSTLCORPSERV;database='booking';user id=sa;password=sqlserver12#");
Con.Open();
Cmd = new SqlCommand("select * from account where uname=@name and password= @pwd", Con);
Cmd.Parameters.Add("@name", SqlDbType.VarChar);
Cmd.Parameters.Add("@pwd", SqlDbType.VarChar);
Cmd.Parameters[0].Value = textBox1.Text;
Cmd.Parameters[1].Value = textBox2.Text;
Data = Cmd.ExecuteReader();
if (Data.Read() == true)
{

label3.Text = "valid user";
Admin_Page ad = new Admin_Page(textBox1.Text);
ad.Show();
this.Hide();[\code]
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: multiple user authentication..

 
0
  #7
Jan 5th, 2008
add new column in your user table to identify the user type, sure you can't do that using just username and password!!!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: multiple user authentication..

 
0
  #8
Jan 5th, 2008
Come on, man. Add a column "UserType" with a value of 0 or 1. 0 for admin, 1 for user. When you check the username and password, also grab the value from that column.
--
"Dummy."
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: bharathi_n_r is an unknown quantity at this point 
Solved Threads: 0
bharathi_n_r bharathi_n_r is offline Offline
Light Poster

Re: multiple user authentication..

 
0
  #9
Jan 7th, 2008
ok i have added a new column in my user table called utype..In my code i have written
Cmd = new SqlCommand("select * from account where uname=@name and password= @pwd and utype =@type", Con);

            Cmd.Parameters.Add("@name", SqlDbType.VarChar);
            Cmd.Parameters.Add("@pwd", SqlDbType.VarChar);
            Cmd.Parameters.Add("@type", SqlDbType.Int);            Cmd.Parameters[0].Value = textBox1.Text;
            Cmd.Parameters[1].Value = textBox2.Text;
            Data = Cmd.ExecuteReader();
            if (Data.Read(0) == true)
            {

                label3.Text = "valid user";
                Admin_Page ad = new Admin_Page(textBox1.Text);
                ad.Show();
                this.Hide();
            }
                else if (Data.Read(1)==true)                {
                    Seat_Book sb=new Seat_Book();
                    sb.Show();
                    this.Hide();
                }
How to grab that value in my code...
But it is not working.It is saying that no overload for method read takes 1 arguments..Where to use this logic and what code should i use dudes...
I am going to enter only user name and password in my login page...It should fetch the value from the database based on the username i give in textbox1......
Is this possible fellows.....
Last edited by bharathi_n_r; Jan 7th, 2008 at 1:24 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: multiple user authentication..

 
0
  #10
Jan 7th, 2008
Why this "and utype =@type" in your select statement??!!!! you want to filter selected user by utype ??! as you don't know his\her type at all

what you need to modify is to add new column in user table and select userID and uType using user name AND password!

Assign user object ID property with id returned from DB and also uType property (enum).

before calling a method check uType to authorize the current user.

P.S: DataReader.Read() doesn't take any arguments!! to loop for many records (and you don't need that in your case) use while loop

like
  1. while(reader.Read())
  2. {
  3. ///some sort of code goes here!
  4. }
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC