//Verify if user put the correct credentials on login menu and return a playerobject matching those credentials from the database if he did. public PlayerRef GetPlayerByCredentials(string playerName, string pw) { playerList = playerCollection.Find(new BsonDocument()).ToList(); foreach (var playerObject in playerList) { if (playerObject.Name.Equals(playerName)) { var decrypted = PasswordHandler.Decrypt(playerObject.Password, playerObject.Name); if (decrypted.Equals(pw)) { LoginSuccess = true; player = playerObject; hsCollection = playerObject.ScoreCollection; } else { LoginSuccess = false; } } } return(player); }
public ActionResult <Response> Post([FromBody] User user) { try { var fetched_user = appDbContext.Users.SingleOrDefaultAsync(p => p.Email == user.Email); if (fetched_user.Result != null && user.Password == PasswordHandler.Decrypt(fetched_user.Result.Password, "sblw-3hn8-sqoy19")) { HttpContext.Session.SetString("is_login", "true"); HttpContext.Session.SetString("userid", fetched_user.Result.Id.ToString()); return(new Response(null, 200, "Logged in succesfully")); } else { HttpContext.Session.SetString("is_login", "false"); return(new Response(null, 200, "Login Failed")); } } catch (Exception ex) { return(new Response(null, 404, ex.Message)); } }
public ActionResult Post([FromBody] User userObj) { try { User user = appDbContext.User.SingleOrDefault(p => p.Email == userObj.Email); if (user != null && userObj.Password == PasswordHandler.Decrypt(user.Password, "sblw-3hn8-sqoy19")) { string token = authService.Authenticate(user.Email); user.Token = token; user.Password = null; return(Ok(user)); } else { return(BadRequest(new { message = "Email or password is wrong", })); } } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }