c# - Login Credentials are not working properly for Admins & Users -
i have created custom login page project. have given roles followed below
0
superadmin1
admins2
users
the problem here that, login works super admin
part. when create admins , users , try login credentials, gives me error invalid username & password. tried checking , debugging don't know why not working.
please see code button_click
event reference:-
protected void btnsubmit_click(object sender, eventargs e) { string loginid = txtusername.text.trim().tolower(); string loginpassword = txtpassword.text.trim(); sqlconnection conn = new sqlconnection(system.configuration.configurationmanager.connectionstrings["defaultcsrconnection"].connectionstring); conn.open(); sqlcommand cmd = new sqlcommand("select username,password,usertype tbl_user username=@username , password=@password , active=@active", conn); cmd.parameters.addwithvalue("@username", txtusername.text); cmd.parameters.addwithvalue("@password", txtpassword.text); cmd.parameters.addwithvalue("@active", 1); sqldataadapter da = new sqldataadapter(cmd); datatable dt = new datatable(); da.fill(dt); if (dt != null && dt.rows.count > 0) { if (dt.rows[0]["usertype"].tostring() == "0") //superadmin { session["user"] = dt.rows[0]["username"].tostring(); response.redirect("csrdashboards.aspx"); } else if (dt.rows[0]["usertype"].tostring() == "1") // admin { session["user"] = dt.rows[0]["username"].tostring(); response.redirect("csrdashboards.aspx"); } else if (dt.rows[0]["usertype"].tostring() == "2") // user { session["user"] = dt.rows[0]["username"].tostring(); response.redirect("csrdashboards.aspx"); } } else { clientscript.registerstartupscript(page.gettype(), "validation", "<script language='javascript'>alert('invalid username , password')</script>"); } }
please help. let me know if need else.
run query same username , password in sql server management studio , results , know if wrong username , password. if no data returned in sql username or password should incorrect. creating user encrypted password , selecting user plain password.encrypt password before selecting user.
Comments
Post a Comment