示例#1
0
        public static String HashGenerated(String value)
        {
            String salt = Bcrypt.GenerateSalt();
            String hash = Bcrypt.HashPassword(value, salt);

            return(hash);
        }
示例#2
0
        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));
            }
        }
示例#3
0
        /// <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));
        }
示例#4
0
        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 });
        }
示例#5
0
        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
            });
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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();
        }
示例#9
0
 public static string Hash(string password)
 => Crypt.HashPassword(password, Crypt.GenerateSalt(Configuration.WorkFactor));
示例#10
0
 /// <summary>
 /// Генерация соли
 /// </summary>
 /// <returns></returns>
 private static string GetRandomSalt()
 {
     //2^10 итераций по умолчанию
     return(CryptoManager.GenerateSalt());
 }
示例#11
0
 public static string GenerateRandomSalt()
 {
     return(Crypto.GenerateSalt(12));
 }
示例#12
0
 private static string GetRandomSalt()
 {
     return(BC.GenerateSalt(12));
 }
 private string GetRandomSalt()
 {
     return(Bcrypt.GenerateSalt(12));
 }
示例#14
0
 public override string GenerateSalt()
 {
     return(BCN.GenerateSalt());
 }
示例#15
0
 public override string GenerateSalt(int workFactor)
 {
     return(BCN.GenerateSalt(workFactor));
 }