wcf - ASP.NET MVC5 Identity account lockout without Entity Framework -
i have created asp.net mvc5 application allows users access financial data including invoices, services , products have acquired our company.
the application gets data set of wcf services including list of registered users have access system. i'm using asp.net identity object , claims authorize users application, works fine have use credentials (email , password) invoke wcf service returns object containing details user or null value if there's no match.
however, there's new requirement implement account lockout after 5 failed login attempts (the account locked 20 minutes before allowing users try again) feature included in asp.net identity 2.0. have been "googling" couple of days, couldn't find example (or similar approach) of how implement requirement without storing users in entity framework , local db.
is there way of adding account lockout feature (with 20 minutes lockout) using wcf service datasource asp.net mvc5 application? ideas?
this first asp.net mvc5 application, don't know features provided on it, appreciated.
this how login (post) looks like:
//authentication handler iauthenticationmanager authentication { { return httpcontext.getowincontext().authentication; } } [httppost] [allowanonymous] [validateantiforgerytoken] public actionresult login(loginviewmodel model, string returnurl) { if (modelstate.isvalid) { try { //validate user service cwp_accountservice.user userobject = accountclient.getuserbycredentials(model.email, model.password); if (userobject != null) { //create claims var identity = new claimsidentity( new[] { new claim(claimtypes.name, userobject.email) }, defaultauthenticationtypes.applicationcookie, claimtypes.name, claimtypes.role); identity.addclaim(new claim(claimtypes.nameidentifier, userobject.email)); identity.addclaim(new claim(claimtypes.sid, userobject.userid.tostring())); int cookiedurationpersistence = 20160; int cookieduration = 2; authentication.signin(new authenticationproperties { ispersistent = model.rememberme, expiresutc = (model.rememberme) ? datetime.now.addminutes(cookiedurationpersistence) : datetime.now.addminutes(cookieduration) }, identity); //check if there local return url if (url.islocalurl(returnurl) && returnurl.length > 1 && returnurl.startswith("/") && !returnurl.startswith("//") && !returnurl.startswith("/\\")) { return redirecttolocal(returnurl); } return redirecttoaction("index", "home"); } else { modelstate.addmodelerror("system-error", "the email/password provided not valid."); } } catch(exception ex) { modelstate.addmodelerror("system-error", "error"); logger.warn(ex.tostring()); } } return view(model); }
the startup.auth.cs
:
public partial class startup { public void configureauth(iappbuilder app) { // enable application use cookie store information signed in user app.usecookieauthentication(new cookieauthenticationoptions { authenticationtype = defaultauthenticationtypes.applicationcookie, loginpath = new pathstring("/account/login") }); } }
Comments
Post a Comment