Exemplo n.º 1
0
        public async Task SignOutUserAsync(Users userToCreate, string plainPassword)
        {
            string passwordSalt = PasswordHashing.CreateSalt();

            userToCreate.PasswordSalt = passwordSalt;
            userToCreate.PasswordHash = PasswordHashing.GenerateHash(plainPassword, passwordSalt);

            await _context.Users.AddAsync(userToCreate);
        }
Exemplo n.º 2
0
        public bool addAccount(RequestAccount account)
        {
            // try
            // {
            using (SqlConnection connection = new SqlConnection(connectParametr))
                using (SqlCommand command = new SqlCommand()) {
                    command.Connection = connection;
                    connection.Open();

                    string salt            = PasswordHashing.CreateSalt();
                    string hashingPassword = PasswordHashing.Create(account.Password, salt);
                    // salt and password
                    command.CommandText = @" INSERT INTO Student (IndexNumber, FirstName, LastName, BirthDate, IdEnrollment, Password, Salt) " +
                                          " VALUES(@indexNumber, @firstName, @secondName, @birthDate, @idEnrollment, @hashingPassword, @salt); ";
                    command.Parameters.AddWithValue("indexNumber", account.Student.IndexNumber);
                    command.Parameters.AddWithValue("firstName", account.Student.FirstName);
                    command.Parameters.AddWithValue("secondName", account.Student.LastName);
                    command.Parameters.AddWithValue("birthDate", account.Student.BirthDate);
                    command.Parameters.AddWithValue("idEnrollment", account.Student.IdEnrollment);
                    command.Parameters.AddWithValue("hashingPassword", hashingPassword);
                    command.Parameters.AddWithValue("salt", salt);
                    if (command.ExecuteNonQuery() == 0)
                    {
                        return(false);
                    }
                    return(true);
                }

            // }
            //   catch (SqlException sqlException) {
            //   return false;
            // }


            //return true;
        }