public void TryToLogin() { var networkController = UsefulContainer.Instance.Resolve <GameController>().NetworkController; if (networkController == null) { return; } var thread = new Thread(() => { try { networkController.Connect(ip, port); networkController.Username = username.text; networkController.SendPacket(new LoginRequest { GameVersion = 0, Username = username.text, PasswordHash = Argon2Hasher.HashPassword(password.text, username.text) }); } catch (Exception e) { Debug.LogError(e); } }) { IsBackground = true }; thread.Start(); }
protected override Task Handle(LoginRequest packet, ISession session) { var userAccount = _accountService.GetByUsername(packet.Username); if (userAccount == null) { Thread.Sleep( _rng.Next( _hasherConfiguration.HashingMinimumTimeWait, _hasherConfiguration.HashingMaximumTimeWait)); return(Failed(session)); } var serverArgon2 = new Argon2Hasher(userAccount.EncodedHash); if (!serverArgon2.CheckString(packet.PasswordHash)) { return(Failed(session)); } var randomGuid = Guid.NewGuid(); userAccount.SessionId = randomGuid; userAccount.SessionIdExpiryDate = DateTime.UtcNow.AddMinutes(5d); _accountService.Save(userAccount); session.SendPacket( new LoginSucceeded { SessionId = randomGuid.ToString() }); return(Task.CompletedTask); }
public void TryToRegister() { if (Password.text != ConfirmPassword.text) { UsefulContainer.Instance.Resolve <GameController>() .MessageController.SendNoIntrusiveMsg("The provided passwords do not match."); return; } var networkController = UsefulContainer.Instance.Resolve <GameController>().NetworkController; var thread = new Thread(() => { try { networkController.Connect(Ip, Port); networkController.SendPacket(new RegisterRequest() { Key = Key.text, Username = Username.text, PasswordHash = Argon2Hasher.HashPassword(Password.text, Username.text) }); } catch (Exception e) { Debug.LogError(e); } }) { IsBackground = true }; thread.Start(); }
public void TestThatHashVerifiesComplextGreaterTiming() { var secret = "(Thi$) isAn Ev0nM0re c*mple+ S3CR37 --!."; var hasher = new Argon2Hasher(20, 65535, 1); var hashed = hasher.Hash(secret); Assert.True(hasher.Verify(secret, hashed)); }
public void TestThatHashVerifiesComplext() { var secret = "Thi$ isAM0re C*mple+ S3CR37"; var hasher = new Argon2Hasher(10, 65535, 1); var hashed = hasher.Hash(secret); Assert.True(hasher.Verify(secret, hashed)); }
public void TestThatHashVerifiesSimple() { var secret = "secret"; var hasher = new Argon2Hasher(2, 65535, 1); var hashed = hasher.Hash(secret); Assert.True(hasher.Verify(secret, hashed)); }
/// <summary> /// Returns the ArgonHasher with the optimal specs for this PC. /// </summary> public static Argon2Hasher GetBestSettings(HasherConfiguration hasherConfiguration) { /*int tmp; * * if (hasherConfiguration.RamToUseIn_kB == null) * { * tmp = HashUtilities.GetActualFreeMemory() * 25 / 100 / Environment.ProcessorCount; * } * else * { * tmp = (int)hasherConfiguration.RamToUseIn_kB / Environment.ProcessorCount; * } * var m = tmp > minimumMemory ? tmp : minimumMemory;*/ const int minimumMemory = 64 * 1024; var argon2 = new Argon2Hasher { DegreeOfParallelism = hasherConfiguration.ProcessorsToUse == 0 ? Environment.ProcessorCount / 2 : hasherConfiguration.ProcessorsToUse, MemorySize = 1024, Iterations = 1, }; Log.Info("Calculating the optimal parameters..."); var tempArray = new byte[16]; long elapsedMs = -1; while (!(hasherConfiguration.HashingMinimumTimeWait <= elapsedMs && argon2.MemorySize > minimumMemory)) { var watch = System.Diagnostics.Stopwatch.StartNew(); argon2.HashWithSpec(tempArray, tempArray); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; argon2.MemorySize = elapsedMs < hasherConfiguration.HashingMaximumTimeWait ? Convert.ToInt32(argon2.MemorySize * 1.1) : Convert.ToInt32(argon2.MemorySize * 0.9); } Log.Info($"The resultant parameters in {elapsedMs}ms are: {argon2.GetEncodedHash()}"); return(argon2); }
public LoginRequestHandler(IAccountService accountService, Argon2Hasher argon2, LoginConfiguration loginConfiguration) { _accountService = accountService; _argon2 = argon2; _hasherConfiguration = loginConfiguration.HasherConfiguration; }
public RegisterRequestHandler(IAccountService accountService, Argon2Hasher argon2) { _accountService = accountService; _argon2 = argon2; }