ASP.NET MVC 5 Identity 2 PasswordSignInAsync method always returns false -
i'm writing come code external app. i'm trying use microsoft identity 2.0 , asp.net mvc 5. i've customized userviewmodel hold firstname , lastname , couple of other parameters. whenever register user logs in when try normal login email/password. signinmanager.passwordsignasync returns false. since code checks internal framework i'm trying figure out how debug situation. provide code here who's willing @ it. in advance!
that generic login function provided microsoft in examples. i've not changed there. function has error message.
public async task<actionresult> login(loginviewmodel model, string returnurl) { if (!modelstate.isvalid) { return view(model); } // doesn't count login failures towards account lockout // enable password failures trigger account lockout, change shouldlockout: true var result = await signinmanager.passwordsigninasync(model.email, model.password, model.rememberme, shouldlockout: false); switch (result) { case signinstatus.success: return redirecttolocal(returnurl); case signinstatus.lockedout: return view("lockout"); case signinstatus.requiresverification: return redirecttoaction("sendcode", new { returnurl = returnurl, rememberme = model.rememberme }); case signinstatus.failure: default: modelstate.addmodelerror("", "invalid login attempt."); return view(model); } }
this login function
public async task<actionresult> login(loginviewmodel model, string returnurl) { if (!modelstate.isvalid) { return view(model); } // doesn't count login failures towards account lockout // enable password failures trigger account lockout, change shouldlockout: true var result = await signinmanager.passwordsigninasync(model.email, model.password, model.rememberme, shouldlockout: false); switch (result) { case signinstatus.success: return redirecttolocal(returnurl); case signinstatus.lockedout: return view("lockout"); case signinstatus.requiresverification: return redirecttoaction("sendcode", new { returnurl = returnurl, rememberme = model.rememberme }); case signinstatus.failure: default: modelstate.addmodelerror("", "invalid login attempt."); return view(model); } }
this customized identity model
public class applicationuser : identityuser { [displayname("prefix")] public string prefix { get; set; } [displayname("first name")] public string firstname { get; set; } [displayname("last name")] public string lastname { get; set; } [displayname("suffix")] public string suffix { get; set; } public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager) { // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype var useridentity = await manager.createidentityasync(this, defaultauthenticationtypes.applicationcookie); // add custom user claims here return useridentity; } } public class applicationdbcontext : identitydbcontext<applicationuser> { public applicationdbcontext() : base("defaultconnection", throwifv1schema: false) { } public static applicationdbcontext create() { return new applicationdbcontext(); } public system.data.entity.dbset<jbiplacementtracking.models.placementviewmodel> placementviewmodels { get; set; } public system.data.entity.dbset<jbiplacementtracking.models.placement> placements { get; set; } public system.data.entity.dbset<jbiplacementtracking.models.packetstatus> packetstatus { get; set; } }
i'm wondering if problem might don't have custom loginviewmodel.
i'm in on head right , if has resources i'd appreciate link it.
thanks in advance again!
you using email
username
@ login function. make sure upon registration, email inserted both username
, email
fields. use use trim()
, tolower()
before inserting , after reading, that's rest mind stored in db, , might not necessary. luck.
Comments
Post a Comment