In my ASP.Net application, want to validate username and password of users before logging them into the application. I am using ASP.net Identity framework for membership.
Want to make sure whether the entered username and password exist or not.
something like this one Membership.ValidateUser(username,password)
which was used in default membership but can not be used with ASP.net Identity.
Tried this one but no luck?
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
var user = manager.Find(userName,Password);
Net. In this article we will see how to enforce users to create strong passwords. To validate for strong passwords we will use RegularExpressionValidator with REGEX.
The ASP.NET Identity UserManager class is used to manage users e.g. registering new users, validating credentials and loading user information. It is not concerned with how user information is stored. For this it relies on a UserStore (which in our case uses Entity Framework).
I use something like this:
public static bool ValidateUser(string Email, string Password)
{
var user = UserManager.FindByName(Email);
return SignInManager.UserManager.CheckPassword(user, Password);
}
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
var user = manager.FindByName(Email.Text);
//check for credentials before sign in ..
var validCredentials = signinManager.UserManager.CheckPassword(user, Password.Text);
if (validCredentials)
{
//sample code to run if user's credentials is valid and before login
if(!manager.IsInRole(user.Id, "Administrators"))
{
FailureText.Text = "you need a higher permission level in order to login";
return;
}
}
//then sign in
var result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
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