public static String HashGenerated(String value) { String salt = Bcrypt.GenerateSalt(); String hash = Bcrypt.HashPassword(value, salt); return(hash); }
public async Task <IActionResult> CreateUser([FromBody] User user) { try { if (string.IsNullOrEmpty(user.Username) || string.IsNullOrWhiteSpace(user.Username)) { return(BadRequest("Username is required")); } if (!(await _userRepository.ExistsUsername(user.Username))) { string salt = BC.GenerateSalt(); string hashPassword = BC.HashPassword(user.Password, salt); await _userRepository.CreateUser(user, salt, hashPassword); return(Ok("User created!!")); } else { return(BadRequest("Username ja utilizado")); } } catch (System.Exception ex) { return(StatusCode(StatusCodes.Status400BadRequest, ex.Message)); } }
/// <summary> /// Create hash of an input string. /// </summary> /// <param name="input">String data to hash.</param> /// <returns>Hashed string data.</returns> public string CreateHash(string input) { if (input.IsNullOrEmpty()) { return(null); } var salt = Bcrypt.GenerateSalt(); return(Bcrypt.HashPassword(input, salt)); }
public async Task Register(UserDto userDto) { if (await _dbConnection.QueryFirstOrDefaultAsync("SELECT email FROM users WHERE email=@email", new { email = userDto.Email }) != null) { throw new ServiceException(409, "User already exists"); } var hashedPassword = BC.HashPassword(userDto.Password, BC.GenerateSalt()); await _dbConnection.ExecuteAsync("INSERT INTO users(email, password_hash) VALUES (@email, @password_hash)", new { email = userDto.Email, password_hash = hashedPassword }); }
public static SecuredPwdInfo SecurePwd(string plainPwd, string blackPepper, int workForceLevel = 11) { var salt = BCryptNet.GenerateSalt(); var redPepper = BCryptNet.GenerateSalt(); var hashedPwd = Hasher(plainPwd, salt, redPepper, blackPepper, workForceLevel); return(new SecuredPwdInfo { RedPepper = redPepper, Salt = salt, SecuredPwd = hashedPwd }); }
public static User Create(string username, string password) { var salt = BCrypts.GenerateSalt(); var user = new User { Username = username ?? throw new ArgumentNullException(nameof(username)), Password = BCrypts.HashPassword(password ?? throw new ArgumentNullException(nameof(password)), salt), Salt = salt, CreatedTime = DateTime.UtcNow }; return(user); }
public async Task <bool> CreateUserAsync(Usuario user, string password, Role role = Role.NaoAutorizado) { var salt = BC.GenerateSalt(_workFactor); var hash = BC.HashPassword(password, salt); user.HashedPassword = Encoding.ASCII.GetBytes(hash); user.Salt = Encoding.ASCII.GetBytes(salt); user.Role = role; _db.Usuarios.Add(user); return(await _db.SaveChangesAsync() == 1); }
protected void Button1_Click(object sender, EventArgs e) { Usuario usuario = new Usuario(); usuario.Username = TextBoxUsuario.Text; string miPassword = TextBoxPassword.Text; string miSal = BC.GenerateSalt(); string miHash = BC.HashPassword(miPassword, miSal); usuario.Password = miHash; usuario.Nivel = Convert.ToInt32(RadioButtonListNivel.SelectedValue); usuarios.Add(usuario); Guardar(); }
public static string Hash(string password) => Crypt.HashPassword(password, Crypt.GenerateSalt(Configuration.WorkFactor));
/// <summary> /// Генерация соли /// </summary> /// <returns></returns> private static string GetRandomSalt() { //2^10 итераций по умолчанию return(CryptoManager.GenerateSalt()); }
public static string GenerateRandomSalt() { return(Crypto.GenerateSalt(12)); }
private static string GetRandomSalt() { return(BC.GenerateSalt(12)); }
private string GetRandomSalt() { return(Bcrypt.GenerateSalt(12)); }
public override string GenerateSalt() { return(BCN.GenerateSalt()); }
public override string GenerateSalt(int workFactor) { return(BCN.GenerateSalt(workFactor)); }