Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a login from where check userid and password correct or not ?if correct redirect or stay in login page .for that I write bellow code .

C#
public class LoginController : Controller
    {
       public ActionResult Index()
        {
            return View();
        }

        public ActionResult CheckUser(string UserName,string Password)
        {
           
             if ("user authenticate" == true)
            {
                return RedirectToAction("Index", "home");
            }
            else
            {
                return RedirectToAction("Index", "Login");
            }
        }
}


So if a user not authenticate then also a redirection occurred.
Is it possible the redirection is for one time only.if user authenticate,other wise not.
Posted

1 solution

use this code for Authentication:
 con.Open();
                cmd = new SqlCommand("Select * from Registration  where Email='"+Email+"' And Password='"+Pass+"'"), con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
Session["UserId"] = dt.Rows[0]["UserId"].ToString();
                

                    return RedirectToAction("Index", "Dashboard");

                }
                else
                {
                 
                  

                    return RedirectToAction("Index", "Login");
                }
                con.Close();
 
Share this answer
 
Comments
Richard Deeming 15-Jan-15 8:34am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

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