use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project molgenis by molgenis.
the class MolgenisPasswordEncoderTest method encode.
@Test
public void encode() {
String password = "password";
String encodedPassword = "encoded-password";
BCryptPasswordEncoder bCryptPasswordEncoder = mock(BCryptPasswordEncoder.class);
when(bCryptPasswordEncoder.encode(password)).thenReturn(encodedPassword);
assertEquals(new MolgenisPasswordEncoder(bCryptPasswordEncoder).encode(password), encodedPassword);
}
use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project fw-cloud-framework by liuweijw.
the class UserController method modifyUser.
/**
* 修改用户密码
*/
@RequestMapping(value = "/modifyUser", method = RequestMethod.POST)
@PrePermissions(value = Functional.UPD)
public R<Boolean> modifyUser(HttpServletRequest request, @RequestBody UserForm userForm) {
if (null == userForm.getUsername())
return new R<Boolean>().failure("用户名不存在");
if (null == userForm.getPassword())
return new R<Boolean>().failure("请输入旧密码");
if (null == userForm.getNewpassword())
return new R<Boolean>().failure("请输入新密码");
User user = this.userService.findUserByUsername(userForm.getUsername().trim(), false);
if (null == user)
return new R<Boolean>().failure("用户名不存在");
if (!new BCryptPasswordEncoder().matches(userForm.getPassword().trim(), user.getPassword()))
return new R<Boolean>().failure("旧密码输入错误!");
user.setPassword(new BCryptPasswordEncoder().encode(userForm.getNewpassword().trim()));
boolean r = this.userService.updateUser(user);
return new R<Boolean>().data(r);
}
use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project SoftUni by kostovhg.
the class UserController method registerProcess.
@PostMapping("/register")
public String registerProcess(UserBindingModel userBindingModel) {
if (!userBindingModel.getPassword().equals(userBindingModel.getConfirmPassword())) {
return "redirect:/register";
}
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
User user = new User(userBindingModel.getEmail(), userBindingModel.getFullName(), bCryptPasswordEncoder.encode(userBindingModel.getPassword()));
Role userRole = this.roleRepository.findByName("ROLE_USER");
user.addRole(userRole);
this.userRepository.saveAndFlush(user);
return "redirect:/login";
}
use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project mots by motech-implementations.
the class SecurityConfiguration method authenticator.
/**
* Initializes AuthenticationProvider bean with userDetailsService and BCryptPasswordEncoder.
*
* @return initialized AuthenticationProvider
*/
@Bean
public AuthenticationProvider authenticator() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
provider.setPasswordEncoder(new BCryptPasswordEncoder());
return provider;
}
use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project mots by motech-implementations.
the class UserService method saveUser.
/**
* Save User with new encoded password (if it's not blank).
*
* @param user User to be created.
* @return saved User
*/
@PreAuthorize(RoleNames.HAS_MANAGE_USERS_OR_MANAGE_INCHARGE_USERS_ROLE)
public User saveUser(User user, boolean encodeNewPassword) {
if (encodeNewPassword) {
String newPasswordEncoded = new BCryptPasswordEncoder().encode(user.getPassword());
user.setPassword(newPasswordEncoded);
}
return validateAndSave(user);
}
Aggregations