public AuthenticationResult Authenticate(HttpRequestMessage requestMessage) { //if (!requestMessage.RequestUri.PathAndQuery.Contains("clientid", System.StringComparison.OrdinalIgnoreCase)) { // return new AuthenticationResult { IsAuthenticated = false, ErrorCode = 401, Reason = "You must provide your Client ID." }; //} var credentials = _httpRequestMessageHandler.GetCredentials(requestMessage); if (credentials == null) { return new AuthenticationResult { IsAuthenticated = false, ErrorCode = 401, Reason = "You must provide user and Password." } } ; var user = _userManager.GetUser(credentials.UserName); if (user == null) { return new AuthenticationResult { IsAuthenticated = false, ErrorCode = 401, Reason = "User does not exist" } } ; var salt = user.salt; var hashedPassword = _hashHelper.GetHash(credentials.Password + salt); if (user.hashedpassword == hashedPassword) { var token = _tokenHelper.BuildToken(credentials.UserName, "sitaonair", "wms"); //requestMessage.Headers.GetValues("RemoteAddress")?.FirstOrDefault() return(new AuthenticationResult { IsAuthenticated = true, Username = credentials.UserName, Token = token, Regenerate = true }); } return(new AuthenticationResult { IsAuthenticated = false, ErrorCode = 401, Reason = "Authentication failed. Wrong Password" }); } } }
public void Seed() { if (_context.Users.Any(u => u.username == "yodeski")) { return; } var salt = _hashHelper.GetSalt(); var user = new WMSUser { username = "******", useremail = "*****@*****.**", userfullname = "Yodeski Rodriguez Alvarez", salt = salt, creationdate = DateTime.Now, hashedpassword = _hashHelper.GetHash("lolo" + salt) }; _context.Users.Add(user); _userManager.CreateUserShema("yodeski"); if (_context.Maps.Any(u => u.mapname == "canada")) { return; } var map = new WMSMaps { mapname = "canada", mapprojection = "EPSG:3857", username = "******", mapfile = "canada.map", center = "0, 0", zoom = 2 }; _context.Maps.Add(map); _context.SaveChanges(); }