I want to have log in password verification in my project.when user clicks on the log in button compiler goes to this method
public ActionResult VerifyPassword(User user)
{
var givenPassword =user.Password;
var givenUserName=user.UserName;
//now i need compare password
var myUser=db.User.Find(somevalue)//find user from database,
But how can i do this????Because somevalue needs to be a Primary Key
}
If i am doing something wrong.Please point me into right direction I searched a lot on the Web.But no tutorial was found to accomplish this using entity framework.
ASP.NET MVC provides three ways (TempData, ViewData and ViewBag) to manage session, apart from that we can use session variable, hidden fields and HTML controls for the same. But like session variable these elements cannot preserve values for all requests; value persistence varies depending the flow of request.
Authentication. Authentication of user means verifying the identity of the user. This is really important. You might need to present your application only to the authenticated users for obvious reasons. Let's create a new ASP.Net MVC application.
You actually don't need a primary key to match a user in your database.
You can use their username (which should be unique) to locate their record in the database.
Try something like this:
public ActionResult VerifyPassword(User user)
{
//The ".FirstOrDefault()" method will return either the first matched
//result or null
var myUser = db.Users
.FirstOrDefault(u => u.Username == user.Username
&& u.Password == user.Password);
if(myUser != null) //User was found
{
//Proceed with your login process...
}
else //User was not found
{
//Do something to let them know that their credentials were not valid
}
}
Also consider doing a bit of research on Model validation, looking into ModelState.IsValid
is a great start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With