use of org.springframework.security.authentication.encoding.ShaPasswordEncoder in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class StudentController method updatePassword.
@PreAuthorize("hasAnyRole('ROLE_STUDENT')")
@RequestMapping(value = "/update_password", method = RequestMethod.POST)
@ResponseBody
public String updatePassword(Principal principal, @RequestParam("password1") String pass1, @RequestParam("password2") String pass2, @RequestParam("password") String pass) throws NoSuchAlgorithmException {
Student s = studentService.findOne(studentService.findByUsername(principal.getName()).getId());
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String oldPassHash = encoder.encodePassword(pass, null);
String newPassHash = encoder.encodePassword(pass1, null);
if (pass1.length() < 5)
return "Prekratak password";
if (!s.getPassword().equals(oldPassHash))
return "Pogresan stari password";
if (!pass1.equals(pass2))
return "Passwordi razliciti";
if (studentService.updatePassword(studentService.findByUsername(principal.getName()).getId(), newPassHash) == 0)
return "ERROR";
return "Password promijenjen";
}
Aggregations