Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am developing a software in that three users authentication but i want that first admin logged in then another user logged if admin not logged then no one can logged in
Posted
Comments
F-ES Sitecore 5-Aug-15 7:17am    
Your site doesn't know who else is "logged in" as the web is stateless. Any attempt to have the site know when someone else is logged in is doomed to fail. You're going to spend all day "unlocking"\"locking" the site because the admin user simply timed out.

you need to set the flag say "AccountStatus" (0, 1 where 0 represents the deactivated account and 1 represents the account is activated) in database. initially for admin it should be 1 and for other users it should be 0.


At the time of login you need for check the "AccountStatus" field value, If "AccountStatus" is 1 then only user can able to login.


Once the admin logs in, you can update the "AccountStatus" flag for other users to 1 by running the update query just after the success message or before the next page loads completely or you can give the option to admin to activate the selected user's account.


Now its upto you, which way you want to do.


I hope this will solve your problem.


Thanks

 
Share this answer
 
v2
Comments
Member 10918355 5-Aug-15 6:42am    
Dear i understand ur logic but i am unable to write code so can you see my code here
i am posting the code ..
private void button1_Click(object sender, EventArgs e)
{

if (UserType.Text == "Admin")
{
string u = uname.Text;
string p = pass.Text;
SqlConnection con = new SqlConnection("Data Source=KAMAKHYA-PC\\SQLEXPRESS;Initial Catalog=CG;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from UserLogin where UserName='" + u + "' and Pass='" + p + "'", con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
if (dataSet.Tables[0].Rows.Count > 0)
{
MainWindow main = new MainWindow();
main.Show();
uname.Text = "";
pass.Text = "";

}
else
{
MessageBox.Show("Enter Valid User/Password");
uname.Text = "";
pass.Text = "";
}

int i = 1;
SqlCommand comm = new SqlCommand();
string myInsertQuery = "UPDATE [UserLogin] SET [UserStatus] = @UserStatus WHERE [UserType] = '" + UserType.Text + "'";
comm.CommandText = myInsertQuery;
comm.Connection = con;
//con.Open();
comm.Parameters.AddWithValue("@UserStatus", i.ToString());
comm.ExecuteNonQuery();
con.Close();
comm.Connection.Close();


after that can you write code for me ... if it is possbile ....in short form

i have a combobox with thee authentication admin supervisor and user
so please if it is possbile then write code in short form i will understand
Member 10918355 5-Aug-15 8:31am    
please help me if .... i am new for this type of authentication... so only you write code in short form... i will implement that

Hi
U have to capture login user in one table,once user or admin login u have to insert user name and its authentication.

If admin login u have to capture name and its authentication type,once admin logout u delete admin entry form that table.


So finally other than admin if login ,first check admin is logged or not using that table,if admin already logged in then allow other user,if not then show message admin not login.


But why u want first admin need to login and then other user allow to login ?
If admin leave on some days,then nobody(other than admin users) cant login,


Is this u want ?

 
Share this answer
 
v2
Comments
Member 10918355 5-Aug-15 6:41am    
dear this is my code of login
for admin
private void button1_Click(object sender, EventArgs e)
{

if (UserType.Text == "Admin")
{
string u = uname.Text;
string p = pass.Text;
SqlConnection con = new SqlConnection("Data Source=KAMAKHYA-PC\\SQLEXPRESS;Initial Catalog=CG;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from UserLogin where UserName='" + u + "' and Pass='" + p + "'", con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
if (dataSet.Tables[0].Rows.Count > 0)
{
MainWindow main = new MainWindow();
main.Show();
uname.Text = "";
pass.Text = "";

}
else
{
MessageBox.Show("Enter Valid User/Password");
uname.Text = "";
pass.Text = "";
}

int i = 1;
SqlCommand comm = new SqlCommand();
string myInsertQuery = "UPDATE [UserLogin] SET [UserStatus] = @UserStatus WHERE [UserType] = '" + UserType.Text + "'";
comm.CommandText = myInsertQuery;
comm.Connection = con;
//con.Open();
comm.Parameters.AddWithValue("@UserStatus", i.ToString());
comm.ExecuteNonQuery();
con.Close();
comm.Connection.Close();



can you write code in short form.... for me.... if it is possible to u
Member 10918355 5-Aug-15 7:47am    
Dear i m developing software for data entry so first admin login then another user logged in ..... so for but i am unable to coding bcse its for me first time this type of authentication so if u help me than i am so thnaksful to u
Aravindba 5-Aug-15 21:25pm    
Your are asking in asp.net(web application) or windows application ? How u can write this code in asp.net ???
MainWindow main = new MainWindow();
main.Show();
Clearly ask ur question and its tag.Question and tag specify asp.net but ur code in windows application,update ur question and tag correctly.Even though u dont know which environment u work on ?
Aravindba 5-Aug-15 21:48pm    
I thought based on ur code,admin user directly goto each system and open application with admin type,and then ordinary user login with its username and password.

May be u create 2 login forms ,1st login form for admin type and 2nd login form other user type.so admin user login first and it open 2nd login form ,so now other user login with 2nd login form.

Finally what i say first application opened by admin user in each system and it prompt 2nd login form for other ordinary user login.So in window application start up page as login1 form and proceed with login2 form,if ordinary or superuser successfully enter username and password in login2 form then open Main form .

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