/// <summary> /// hashes the password, then adds the user to the database /// </summary> /// <param name="user">the user that will be added</param> /// <returns>if the user got added</returns> public bool AddUser(User user) { if (user.Password.Length > 5) { byte[] passwordByte = Encoding.UTF8.GetBytes(user.Password); byte[] salt = hashing.GenerateSalt(32); user.Password = Convert.ToBase64String(hashing.ComputeMAC(passwordByte, salt)); user.Salt = Convert.ToBase64String(salt); return(dataManager.AddUser(user)); } return(false); }
/// <summary> /// hashes the password, then adds the user to the database /// </summary> /// <param name="username">the username of the user</param> /// <param name="password">the password of the user</param> /// <returns></returns> public bool AddUser(string username, string password) { if (password.Length > 5) { byte[] passwordByte = Encoding.UTF8.GetBytes(password); byte[] salt = hashing.GenerateSalt(32); password = Convert.ToBase64String(hashing.ComputeMAC(passwordByte, salt)); User user = new User(); user.Password = password; user.Username = username; user.Salt = Convert.ToBase64String(salt); return dataManager.AddUser(user); } return false; }
/// <summary> /// hashes the users input /// </summary> public void InputChanges(object obj = null) { // Creates the Hashing object if it is managed or not if (selectedHashing.Managed) { hashing = new Hashing(); } else { hashing = new HmacHashing(); } // Sets the hashingtype hashing.SetHashingType(selectedHashing.Name); // Converts the message to bytes using ascii byte[] message = Encoding.ASCII.GetBytes(this.message); // Hashes the message Time = hashing.ComputeMAC(ref message, Encoding.ASCII.GetBytes(key)); hashed = message; // Updates the output UpdateOutput(obj); // Validates the generatede mac with the inputed mac Validate(obj); }