public void WhenEncryptPassword_ReturnHashAndSalt() { //Act var encrypted = _sut.CreateHash(ValidPassword); //Then encrypted.Should().Not.Be.Null(); encrypted.Hash.Should().Not.Be.Empty(); encrypted.Salt.Should().Not.Be.Empty(); }
public void CreateUser(User user) { user.Id = Guid.NewGuid(); user.Password = PasswordHasher.CreateHash(user.Password, _configuration["Auth:Salt"]); _context.Users.Add(user); }
public void HasherTest_01() { IPasswordHasher passHasherService = new PasswordHasher(); var passHash = passHasherService.CreateHash("admin"); Assert.True(passHasherService.Check(passHash, "admin")); }
public void WhenPasswordValidAndUsernameInvalid_ThenThrows() { dto.Username = String.Empty; dto.PasswordHash = PasswordHasher.CreateHash("apasswordhash"); Assert.Throws <ValidationException>(Resources.CreateUserAccountValidator_InvalidUsername, () => validator.ValidateAndThrow(dto)); }
protected void SignUp_Click(object sender, EventArgs e) { equipment equip = new equipment(); if (lblRogueHidden.Text != "") { newUser.character = lblRogueHidden.Text; } else if (lblGambitHidden.Text != "") { newUser.character = lblGambitHidden.Text; } else if (lblMagikHidden.Text != "") { newUser.character = lblMagikHidden.Text; } else if (lblColossusHidden.Text != "") { newUser.character = lblColossusHidden.Text; } SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["xmenContext"].ToString()); SqlCommand cmd = new SqlCommand("SELECT * FROM characterStats WHERE name = @character;", conn); cmd.Parameters.AddWithValue("@character", newUser.character); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { newUser.charHealth = Convert.ToInt32(dr["health"].ToString()); newUser.atk = Convert.ToInt32(dr["charAtk"].ToString()); newUser.def = Convert.ToInt32(dr["charDef"].ToString()); newUser.speed = Convert.ToInt32(dr["charSpeed"].ToString()); } string password = txtPassword.Text; PasswordHasher PH = new PasswordHasher(); string hashed = PH.CreateHash(password); newUser.firstName = txtFName.Text; newUser.lastName = txtLName.Text; newUser.password = hashed; newUser.email = txtEmail.Text; newUser.equipId = equip.equipId; Session.Add("user", newUser); Session.Add("equipment", equip); xmenContext context = new xmenContext(); context.users.Add(newUser); context.equipments.Add(equip); try { context.SaveChanges(); } catch (DbUpdateException ex) { Console.Write(ex.Message); } FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false); Response.Redirect("LevelOne.aspx"); }
public void CreateOrg() { Organisation organisation = new Organisation { Name = "Lukas coola ställe", Email = "*****@*****.**", Password = PasswordHasher.CreateHash("12345") }; _or.Add(organisation); }
public async Task <TokensResponse> RegisterAsync(RegisterModel registerModel) { var newUser = _mapper.Map <User>(registerModel); newUser.PasswordHash = PasswordHasher.CreateHash(registerModel.Password); _context.Users.Add(newUser); await _context.SaveChangesAsync(); return(await _tokenProvider.GenerateTokensAsync(newUser)); }
public void DummyTest() { IPasswordHasher passHasherService = new PasswordHasher(); var passwordToTest = "ion"; var passHash = passHasherService.CreateHash(passwordToTest); _testOutputHelper.WriteLine($"{passwordToTest} -> {passHash}"); Assert.True(true); }
public async Task <Result <int> > Handle(CanUserSignInQuery request, CancellationToken cancellationToken) { var passwordHash = PasswordHasher.CreateHash(request.Password); Expression <Func <User, bool> > searchExpression = u => u.Email == request.Email && u.PasswordHash == passwordHash; var user = await _userRepository.FindSingleAsync(searchExpression); var areValidCredentials = user != null; return(areValidCredentials ? Result.Ok(user.Id) : Result.Fail <int>("Credentials are invalid")); }
public static SystemUser Create(string name, string email, string password, Guid systemRoleId, UserStatus userStatus, DateTime creatTime) { return(new SystemUser { Name = name, IsActive = Convert.ToBoolean(userStatus), PasswordHash = PasswordHasher.CreateHash(password), Email = email, CreateTime = creatTime, SystemRoleId = systemRoleId }); }
// Metode der skal gemme en kunde i databasen med de angivne parametre. public bool SaveCustomer(Customer aCustomer) { bool result = false; string insertString; // hash the password and get the salt PasswordHasher passwordHasher = new PasswordHasher(); passwordHasher.CreateHash(aCustomer.Password); string hashedPassword = passwordHasher.HashedPassword; string salt = passwordHasher.PasswordSalt; insertString = "INSERT INTO Customer(firstName, lastName, street, houseNo, zipCode, email, phoneNumber, passwordSalt, hashedPassword) VALUES (@FirstName, @LastName, @Street, @HouseNo, @ZipCode, @Email, @PhoneNumber, @PasswordSalt, @HashedPassword)"; try { // Opretter forbindelse til databasen og bruger stringen til at sætte informationer ind på parametrene using (SqlConnection con = new SqlConnection(_connectionString)) using (SqlCommand createCommand = new SqlCommand(insertString, con)) { // Indsætter kundens informationer. SqlParameter fNameParam = new SqlParameter("@FirstName", aCustomer.FirstName); createCommand.Parameters.Add(fNameParam); SqlParameter lNameParam = new SqlParameter("@LastName", aCustomer.LastName); createCommand.Parameters.Add(lNameParam); SqlParameter CustStreetParam = new SqlParameter("@Street", aCustomer.Street); createCommand.Parameters.Add(CustStreetParam); SqlParameter custNoParam = new SqlParameter("@HouseNo", aCustomer.HouseNo); createCommand.Parameters.Add(custNoParam); SqlParameter zipCodeParam = new SqlParameter("@ZipCode", aCustomer.ZipCode); createCommand.Parameters.Add(zipCodeParam); SqlParameter emailParam = new SqlParameter("@Email", aCustomer.Email); createCommand.Parameters.Add(emailParam); SqlParameter phoneNumberParam = new SqlParameter("@PhoneNumber", aCustomer.PhoneNumber); createCommand.Parameters.Add(phoneNumberParam); SqlParameter passwordSalt = new SqlParameter("@PasswordSalt", salt); createCommand.Parameters.Add(passwordSalt); SqlParameter hashedPasswordParam = new SqlParameter("@HashedPassword", hashedPassword); createCommand.Parameters.Add(hashedPasswordParam); con.Open(); // Eksekverer SQL kommandoen int rows = createCommand.ExecuteNonQuery(); if (rows > 0) { result = true; } } } catch (SqlException ex) { //result = false; throw new Exception("Der opstod en fejl: " + ex.Message); } return(result); }
public void WhenUpdateUserAccountWithNewPasswordAndWrongOldPassword_ThenThrows() { var created = this.CreateNewUserAccount(); var newAccount = new UpdateUserAccount { Id = created, OldPasswordHash = PasswordHasher.CreateHash("wrongpassword"), NewPasswordHash = PasswordHasher.CreateHash("anewpassword"), }; Assert.Throws <InvalidOperationException>(HttpErrorCode.FromHttpStatusCode(HttpStatusCode.BadRequest), () => Client.Put(newAccount)); }
public void CreateHash_EmptyInput_ProducesNonEmptyOutput() { //arrange var input = string.Empty; //act var output = _passwordHasher.CreateHash(input); //assert Assert.AreNotEqual(string.Empty, output); }
protected override CreateUserAccount MakeCreateUserAccount() { counter++; return(new CreateUserAccount { Forenames = "aforename", Surname = "asurname", Username = "******" + counter, MobilePhone = string.Empty, Address = new Address { Town = "atown", }, PasswordHash = PasswordHasher.CreateHash("apasswordhash"), Email = counter + "*****@*****.**", }); }
private static UserAccount CreateUserAccount(ServiceClient client, string username, bool hasPassword) { // Create the account client.CurrentUser = Clients.Test.ClientUserAccount.AuthInfo.Username; CreateUserAccountResponse result = client.Post(new CreateUserAccount { Address = new Address { Town = "atown" }, Email = username + "@test.com", Forenames = username.Replace(".", string.Empty), Surname = username.Replace(".", string.Empty), Username = (hasPassword) ? username : null, PasswordHash = (hasPassword) ? PasswordHasher.CreateHash("apassword") : null, }); return(result.UserAccount); }
private async Task <User> CreateUser(RegisterUserCommand request) { var userRole = await _roleRepository.FindSingleAsync(r => r.Name == Roles.User); var user = new User { Email = request.Email, PasswordHash = PasswordHasher.CreateHash(request.Password), UserRoles = new List <UserRole> { new UserRole { RoleId = userRole.Id } } }; return(user); }
protected static UserBaseDto GetUserBaseDto() { var passwordHash = new PasswordHasher(); var result = passwordHash.CreateHash(BasicUserPassword); return(new UserBaseDto { Email = Guid.NewGuid().ToString("N") + "@wp312312addas.pl", Charges = 300, IsAdmin = false, LastName = "Kamiński", LockedOut = false, LockedTo = null, UnsuccessfulLoginAttempts = 0, Name = "Tomasz", PasswordHash = result.Hash, PasswordSalt = result.Salt }); }
public void WhenUpdateUserAccountWithNewPassword_ThenUpdates() { var created = this.CreateNewUserAccount(); var account = Client.Get(new GetUserAccount { Id = created }); var newPasswordHash = PasswordHasher.CreateHash("anewpassword"); var newAccount = new UpdateUserAccount { Id = created, OldPasswordHash = account.UserAccount.PasswordHash, NewPasswordHash = newPasswordHash, }; var result = Client.Put(newAccount); Assert.Equal(newPasswordHash, result.UserAccount.PasswordHash); }
public void Initialize() { validator = new CreateUserAccountValidator(); dto = new CreateUserAccount { Address = new Address { Street1 = "astreet1", Street2 = "astreet2", Town = "atown", }, Email = "*****@*****.**", Forenames = "forenames", Surname = "asurname", MobilePhone = "+123-045-67 89 10", Username = "******", PasswordHash = PasswordHasher.CreateHash("apasswordhash"), }; }
public void Initialize() { validator = new UpdateUserAccountValidator(); dto = new UpdateUserAccount { Id = Guid.NewGuid().ToString(), Address = new Address { Street1 = "astreet1", Street2 = "astreet2", Town = "atown", }, Email = "*****@*****.**", MobilePhone = "+123-045-67 89 10", Forenames = "forenames", OldPasswordHash = PasswordHasher.CreateHash("apassword"), NewPasswordHash = PasswordHasher.CreateHash("apassword"), Surname = "asurname", }; }
public IActionResult Register([FromForm] UserRegDetails user) { // If there are no existing users with same email address, create new user object and add to database. // Returns success page. Otherwise redirect to home. User test = db.Users.FirstOrDefault(x => x.Email == user.Email); ValidateRegistration test2 = new ValidateRegistration(); if (test2.ValidateDOB(user.DOB) && test2.ValidateEmail(user.Email) && test2.ValidatePassword(user.Password)) { if (test == null) { var result = PasswordHasher.CreateHash(user.Password); User newUser = new User(); newUser.Id = ShortGuid.Shorten(Guid.NewGuid()); newUser.FirstName = user.FirstName; newUser.LastName = user.LastName; newUser.Email = user.Email; newUser.PasswordHash = result[0]; newUser.Salt = result[1]; newUser.DOB = Convert.ToDateTime(user.DOB); newUser.Address = user.Address; db.Users.Add(newUser); db.SaveChanges(); return(View("Success")); } else { ViewData["Error"] = "Error: Account creation failed because email has already been used."; return(View("Register")); } } else { ViewData["Error"] = "Error: Incorrect data was given."; return(View("Register")); } }
protected override void PreHandle(ICrudAction <User> action) { action.ActionAgainst.Password = _passwordHasher.CreateHash(action.ActionAgainst.Password); }
public void SetPassword(string newPassword) { PasswordHash = PasswordHasher.CreateHash(newPassword); }
public static string CreateHash(this string str) { return(PasswordHasher.CreateHash(str)); }
public static void Seed(EshopDbContext context) { context.Users.RemoveRange(context.Users); context.SaveChanges(); // init seed data Random random = new Random(); var users = new List <User>(); var user = new User() { Id = new Guid("c5e75dd1-1661-424d-8745-e9a002563c27"), Username = "******", Password = PasswordHasher.CreateHash("admin123", "AN>1w`YqLNgY})adEzwyQI&qblGW}[5%9MH9de'Ov:R(}U?g/au!>#Mtxk=>@d"), Email = "*****@*****.**", Firstname = "Jarmil", Lastname = "Prdel", ContactId = ContactSeeder.GenerateContact(context) }; users.Add(user); RolesSeeder.MapUserRole(context, user.Id, new Guid("9d8329f1-82f5-4cbb-ba4b-955211457707")); // administrator RolesSeeder.MapUserRole(context, user.Id, new Guid("4e7f583f-d4f1-4d7a-833e-693fbf99b6e9")); // manager RolesSeeder.MapUserRole(context, user.Id, new Guid("7446d1fb-a305-440c-b6d9-53769dc1e08a")); // seller // other dashboard managers for (int i = 0; i < 10; i++) { user = new User() { Id = Guid.NewGuid(), Username = LoremNET.Lorem.Words(1), Email = LoremNET.Lorem.Email(), Password = PasswordHasher.CreateHash("Test123", "AN>1w`YqLNgY})adEzwyQI&qblGW}[5%9MH9de'Ov:R(}U?g/au!>#Mtxk=>@d"), Firstname = LoremNET.Lorem.Words(1), Lastname = LoremNET.Lorem.Words(1), ContactId = ContactSeeder.GenerateContact(context) }; users.Add(user); RolesSeeder.MapUserRole(context, user.Id, new Guid("4e7f583f-d4f1-4d7a-833e-693fbf99b6e9")); // manager } // customers for (int i = 0; i < 4000; i++) { var customer = new User() { Id = Guid.NewGuid(), Username = LoremNET.Lorem.Words(1), Email = LoremNET.Lorem.Email(), Password = PasswordHasher.CreateHash("Test123", "AN>1w`YqLNgY})adEzwyQI&qblGW}[5%9MH9de'Ov:R(}U?g/au!>#Mtxk=>@d"), Firstname = LoremNET.Lorem.Words(1), Lastname = LoremNET.Lorem.Words(1), ContactId = ContactSeeder.GenerateContact(context) }; users.Add(customer); RolesSeeder.MapUserRole(context, customer.Id, new Guid("7bf2bcb3-9eb0-4e0d-a88b-9a6937bdee85")); // customer } context.Users.AddRange(users); context.SaveChanges(); }