c# - How to validate password and redirect admin to admin page and user to user page using roles? -
this code:
protected void loginbtn_click(object sender, eventargs e) { if (ispostback) { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["userdatabaseconnectionstring1"].connectionstring); conn.open(); dataset ds = new dataset(); sqlcommand cmd = new sqlcommand("select role accounts", conn); sqldataadapter da = new sqldataadapter(); cmd.commandtype = commandtype.text; da.selectcommand = cmd; da.fill(ds); if (ds.tables[0].rows.count > 0) { string role = convert.tostring(ds.tables[0].rows[0]["role"]); if (role == "a") { response.redirect("adminpage/adminaccount.aspx"); } if (role == "u") { response.redirect("userpage/useraccount.aspx"); } } else { //record not in ur table } } }
role a
admin, , role u
users.
how validate , redirect users logging in correctly?
right code redirect me admin home page whenever click login, whether or not username , password correct.
what need add in fix this?
you have no idea doing
please make logic trying explain your
sqlcommand cmd = new sqlcommand("select role accounts", conn);
this line return users right?
but need specific users data write this
sqlcommand cmd = new sqlcommand("select role accounts username='"+yourusernametextbox.text+"' , password='"+yourpassword.text+"'--", conn);
this return true result role admin or user
and 1 suggestion you
formatting queries may result sql injection rather please use parametrized queries
Comments
Post a Comment