// POST api/CustomLogin public HttpResponseMessage Post(LoginRequest loginRequest) { homesecurityContext context = new homesecurityContext(); Account account = context.Accounts .Where(a => a.Email == loginRequest.Email).SingleOrDefault(); if (account != null) { byte[] incoming = CustomLoginProviderUtils .hash(loginRequest.Password, account.Salt); if (CustomLoginProviderUtils.slowEquals(incoming, account.SaltedAndHashedPassword)) { ClaimsIdentity claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, loginRequest.Email)); LoginResult loginResult = new CustomLoginProvider(handler) .CreateLoginResult(claimsIdentity, Services.Settings.MasterKey); var customLoginResult = new CustomLoginResult() { UserId = loginResult.User.UserId, MobileServiceAuthenticationToken = loginResult.AuthenticationToken, Verified = account.Verified }; return this.Request.CreateResponse(HttpStatusCode.OK, customLoginResult); } } var message = "Fail"; return this.Request.CreateResponse(HttpStatusCode.Unauthorized, new { message }); }
// POST api/CustomLogin public HttpResponseMessage Post(LoginRequest loginRequest) { ToeTrackerTrainerMobContext context = new ToeTrackerTrainerMobContext(); Account account = context.Accounts .Where(a => a.Username == loginRequest.username).SingleOrDefault(); if (account != null) { byte[] incoming = CustomLoginProviderUtils .hash(loginRequest.password, account.Salt); if (CustomLoginProviderUtils.slowEquals(incoming, account.SaltedAndHashedPassword)) { ClaimsIdentity claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, loginRequest.username)); LoginResult loginResult = new CustomLoginProvider(handler) .CreateLoginResult(claimsIdentity, Services.Settings.MasterKey); var customLoginResult = new CustomLoginResult() { UserId = loginResult.User.UserId, MobileServiceAuthenticationToken = loginResult.AuthenticationToken, UserType = account.Trainer == true ? "Trainer" : "Trainee" }; return(this.Request.CreateResponse(HttpStatusCode.OK, customLoginResult)); } } return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid username or password")); }
// POST api/CustomLogin public HttpResponseMessage Post(LoginRequest loginRequest) { var context = new dhcchardwareContext(); var account = context.Accounts.SingleOrDefault(a => a.Username == loginRequest.username); if (account == null) { return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid username or password")); } byte[] incoming = CustomLoginProviderUtils .hash(loginRequest.password, account.Salt); if (!CustomLoginProviderUtils.slowEquals(incoming, account.SaltedAndHashedPassword)) { return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid username or password")); } var claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, loginRequest.username)); var loginResult = new CustomLoginProvider(handler) .CreateLoginResult(claimsIdentity, Services.Settings.MasterKey); var customLoginResult = new CustomLoginResult() { UserId = loginResult.User.UserId, MobileServiceAuthenticationToken = loginResult.AuthenticationToken }; return(this.Request.CreateResponse(HttpStatusCode.OK, customLoginResult)); }
// POST api/CustomLogin public HttpResponseMessage Post(LoginRequest loginRequest) { XamarinPushDemoContext context = new XamarinPushDemoContext(); Account account = context.Accounts .Where(a => a.Username == loginRequest.username).SingleOrDefault(); if (account != null) { byte[] incoming = CustomLoginProviderUtils .hash(loginRequest.password, account.Salt); if (CustomLoginProviderUtils.slowEquals(incoming, account.SaltedAndHashedPassword)) { ClaimsIdentity claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, loginRequest.username)); LoginResult loginResult = new CustomLoginProvider(handler) .CreateLoginResult(claimsIdentity, Services.Settings.MasterKey); var customLoginResult = new CustomLoginResult() { UserId = loginResult.User.UserId, MobileServiceAuthenticationToken = loginResult.AuthenticationToken }; return this.Request.CreateResponse(HttpStatusCode.OK, customLoginResult); } } return this.Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid username or password"); }
// POST api/CustomLogin public HttpResponseMessage Post(LoginRequest loginRequest) { // TODO: Comment out for Azure Table storage. MobileServiceContext context = new MobileServiceContext(); Account account = context.Accounts .Where(a => a.Username == loginRequest.username).SingleOrDefault(); //// TODO: Uncomment to use Azure Table storage. //// Create a query for a specific username. //TableQuery<Account> query = new TableQuery<Account>().Where( // TableQuery.GenerateFilterCondition("Username", QueryComparisons.Equal, // loginRequest.username)); //// Execute the query to retrieve the account. //Account account = accountTable.ExecuteQuery(query).SingleOrDefault(); if (account != null) { if (!account.IsConfirmed) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "You must first confim your account registration.")); } byte[] incoming = CustomLoginProviderUtils .hash(loginRequest.password, account.Salt); if (CustomLoginProviderUtils.slowEquals(incoming, account.SaltedAndHashedPassword)) { ClaimsIdentity claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, loginRequest.username)); LoginResult loginResult = new CustomLoginProvider(handler) .CreateLoginResult(claimsIdentity, Services.Settings.MasterKey); var customLoginResult = new CustomLoginResult() { UserId = loginResult.User.UserId, MobileServiceAuthenticationToken = loginResult.AuthenticationToken }; return(this.Request.CreateResponse(HttpStatusCode.OK, customLoginResult)); } } return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid username or password")); }