Search in sources :

Example 11 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project nixmash-blog by mintster.

the class UserPasswordControllerTests method loggedInUserPasswordIsUpdated.

@Test
public void loggedInUserPasswordIsUpdated() throws Exception {
    RequestBuilder request = post("/users/resetpassword").param("userId", "4").param("password", "password").param("repeatedPassword", "password").with(csrf());
    mvc.perform(request);
    Optional<User> user = userService.getUserById(4L);
    if (user.isPresent()) {
        String encodedPassword = user.get().getPassword();
        assertTrue(new BCryptPasswordEncoder().matches("password", encodedPassword));
    }
}
Also used : User(com.nixmash.blog.jpa.model.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Test(org.junit.Test)

Example 12 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project spring-thymeleaf-simplefinance by heitkergm.

the class SpringSecurityConfig method configure.

@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 13 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project flytecnologia-api by jullierme.

the class FlyGeneratePassword method main.

public static void main(String[] args) {
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    System.out.println(encoder.encode("admin"));
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 14 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project tutorials by eugenp.

the class DummyContentUtil method generateDummyUsers.

public static final List<AppUser> generateDummyUsers() {
    List<AppUser> appUsers = new ArrayList<>();
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    appUsers.add(new AppUser("Lionel Messi", "lionel@messi.com", passwordEncoder.encode("li1234")));
    appUsers.add(new AppUser("Cristiano Ronaldo", "cristiano@ronaldo.com", passwordEncoder.encode("c1234")));
    appUsers.add(new AppUser("Neymar Dos Santos", "neymar@neymar.com", passwordEncoder.encode("n1234")));
    appUsers.add(new AppUser("Luiz Suarez", "luiz@suarez.com", passwordEncoder.encode("lu1234")));
    appUsers.add(new AppUser("Andres Iniesta", "andres@iniesta.com", passwordEncoder.encode("a1234")));
    appUsers.add(new AppUser("Ivan Rakitic", "ivan@rakitic.com", passwordEncoder.encode("i1234")));
    appUsers.add(new AppUser("Ousman Dembele", "ousman@dembele.com", passwordEncoder.encode("o1234")));
    appUsers.add(new AppUser("Sergio Busquet", "sergio@busquet.com", passwordEncoder.encode("s1234")));
    appUsers.add(new AppUser("Gerard Pique", "gerard@pique.com", passwordEncoder.encode("g1234")));
    appUsers.add(new AppUser("Ter Stergen", "ter@stergen.com", passwordEncoder.encode("t1234")));
    return appUsers;
}
Also used : ArrayList(java.util.ArrayList) AppUser(com.baeldung.models.AppUser) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 15 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project mots by motech-implementations.

the class UserService method registerNewUser.

/**
 * Create User with new encoded password.
 *
 * @param user User to be created.
 * @return created User
 */
@PreAuthorize(RoleNames.HAS_MANAGE_USERS_OR_MANAGE_INCHARGE_USERS_ROLE)
public User registerNewUser(User user) {
    String newPasswordEncoded = new BCryptPasswordEncoder().encode(user.getPassword());
    user.setPassword(newPasswordEncoded);
    return validateAndSave(user);
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)48 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)18 Test (org.junit.jupiter.api.Test)7 KeystorePasswordHolder (won.owner.model.KeystorePasswordHolder)7 User (won.owner.model.User)7 SCryptPasswordEncoder (org.springframework.security.crypto.scrypt.SCryptPasswordEncoder)6 DelegatingPasswordEncoder (org.springframework.security.crypto.password.DelegatingPasswordEncoder)5 NoOpPasswordEncoder (org.springframework.security.crypto.password.NoOpPasswordEncoder)5 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)5 StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)5 User (com.github.liuweijw.business.admin.domain.User)4 HashMap (java.util.HashMap)4 Transactional (org.springframework.transaction.annotation.Transactional)4 KeystoreHolder (won.owner.model.KeystoreHolder)4 ExpensiveSecureRandomString (won.protocol.util.ExpensiveSecureRandomString)4 PrePermissions (com.github.liuweijw.business.commons.web.aop.PrePermissions)3 Date (java.util.Date)3 lombok.val (lombok.val)3 Bean (org.springframework.context.annotation.Bean)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3