Example usage for org.springframework.security.crypto.bcrypt BCryptPasswordEncoder encode

List of usage examples for org.springframework.security.crypto.bcrypt BCryptPasswordEncoder encode

Introduction

In this page you can find the example usage for org.springframework.security.crypto.bcrypt BCryptPasswordEncoder encode.

Prototype

public String encode(CharSequence rawPassword) 

Source Link

Usage

From source file:com.mycompany.fitness_tracker_servlet_maven.core.PasswordEncoder.java

protected static String hashPassword(String aPassword) {
    log.trace("hashPassword");
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(PASSWORD_STRENGTH);
    return passwordEncoder.encode(aPassword);
}

From source file:no.ntnu.okse.web.WebSecurityConfig.java

public static boolean changeUserPassword(String password) {
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    String hashedPW = encoder.encode(password);
    try {/*from  w  w w .j  a  v a 2s .  co  m*/
        DB.conDB();
        DB.changePassword("admin", hashedPW);
    } catch (SQLException e) {
        log.debug("Unable to change password for admin user");
        return false;
    }
    return true;
}

From source file:com.wms.utils.DataUtil.java

public static String BCryptPasswordEncoder(String password) {
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    return passwordEncoder.encode(password);
}

From source file:com.mycompany.hash.HashCode.java

public String getHashPassword(String password) {
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(12);
    String hashedPassword = passwordEncoder.encode(password);

    System.out.println(hashedPassword);
    return hashedPassword;
}

From source file:com.mycompany.loginApp.Service.UserService.java

@Override
public void saveUser(User user) {
    BCryptPasswordEncoder encode = new BCryptPasswordEncoder();
    user.setPassword(encode.encode(user.getPassword()));
    List<Role> roles = new ArrayList<Role>();
    roles.add(roleDao.findByName("ROLE_USER"));
    user.setRoles(roles);/*ww  w.ja  v a  2 s .  co  m*/
    userDao.save(user);
}

From source file:com.wury.app.controller.PageController.java

@RequestMapping(value = "/sign-up", method = RequestMethod.POST)
public String registerAuthor(@ModelAttribute("newAuthor") Author newAuthor, BindingResult result,
        RedirectAttributes attributes) {
    Role role = roleService.fineOne(1);
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    newAuthor.setPassword(encoder.encode(newAuthor.getPassword()));
    newAuthor.setRole(role);// w w w.jav  a 2s .c  o  m
    newAuthor.setEnabled(true);
    authorService.save(newAuthor);
    attributes.addFlashAttribute("sign-up", true);
    return "redirect:home";
}

From source file:com.mtech.easyexchange.mvc.RegisterController.java

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String processRegistration(@Valid @ModelAttribute("user") User user, BindingResult bindingResult) {

    registrationValidator.validate(user, bindingResult);

    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(10);

    user.setPassword(encoder.encode(user.getPassword()));

    if (bindingResult.hasErrors()) {
        return "user/register";
    }//  w  ww. j  a va  2  s . c o  m

    try {
        userManager.createUser(user);
    } catch (UserAlreadyExistsException e) {
        return "user/register";
    }

    return "redirect:/register/thank-you";
}

From source file:com.mycompany.loginApp.Service.InitDb.java

@Transactional
public void init() {
    Role roleAdmin = new Role();
    roleAdmin.setName("ROLE_ADMIN");
    roleDao.save(roleAdmin);//w  ww .jav a 2  s. com

    Role roleUser = new Role();
    roleUser.setName("ROLE_USER");
    roleDao.save(roleUser);

    User userAdmin = new User();
    userAdmin.setUsername("admin");
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    userAdmin.setPassword(encoder.encode("admin"));
    List<Role> roles = new ArrayList<Role>();
    roles.add(roleAdmin);
    roles.add(roleUser);
    userAdmin.setRoles(roles);
    userDao.save(userAdmin);

}

From source file:tld.mydomain.example.core.service.ExampleAccountService.java

@Transactional
public void createAccount(ExampleAccount newAccount, String newPassword) {
    if (null != newAccount.getId()) {
        throw new RuntimeException("Cannot create account: account already persisted.");
    }/*from   www.j a v a  2s  .c  o  m*/

    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    newAccount.setPassword(encoder.encode(newPassword));

    newAccount.setEmailConfirmCode(UUID.randomUUID().toString());
    newAccount.setEmailConfirmed(true);
    newAccount.setEmailConfirmedDate(ZonedDateTime.now());

    newAccount.setEnabled(true);

    accountRepository.save(newAccount);
}

From source file:edu.mum.service.impl.UserServiceImpl.java

@Override
public void save(User user) {
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    user.getCredentials().setEnabled(true);
    user.getCredentials().setPassword(encoder.encode(user.getCredentials().getPassword()));
    //        String authorityName = user.getCredentials().getAuthority().getName();

    userDao.save(user);/*from www .  jav a  2s.  c  om*/

}