public ActionResult <User> GetAuthToken(string username, string password) { User LoginData = new User() { username = username, password = password }; List <User> Users = SingleTon.GetSQLAccessor().GetUser(); foreach (User element in Users) { if (element.username == LoginData.username) { User CurrentUser = element; if (SingleTon.GetCryptoHashing().VerifyHash(LoginData.password, element.password)) { Claim[] claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, element.userID) }; SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SingleTon.readSetting("secret"))); string Algo = SecurityAlgorithms.HmacSha256; SigningCredentials signingCredentials = new SigningCredentials(key, Algo); JwtSecurityToken token = new JwtSecurityToken(SingleTon.readSetting("issuer"), SingleTon.readSetting("audiance"), claims, notBefore: DateTime.Now, expires: DateTime.Now.AddDays(1), signingCredentials); CurrentUser.password = ""; CurrentUser.token = new JwtSecurityTokenHandler().WriteToken(token); return(Ok(CurrentUser)); } } } return(BadRequest()); }
public void CreateAccount(User newAccount) { SqlConnection connection; if (OpenConnection(out connection)) { //Create Account SqlCommand command = connection.CreateCommand(); command.CommandText = "INSERT into Account " + "(UserID, Username, Password) VALUES('" + Guid.NewGuid() + "','" + newAccount.username + "','" + SingleTon.GetCryptoHashing().HashPassword(newAccount.password) + "')"; command.ExecuteNonQuery(); //Create Player command = connection.CreateCommand(); //Write in Chat new user //AddItems To player Inventory CloseConnection(connection); } }