56789101112131415
public class PasswordUtils { public static String encodePassword(String password) { BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor(); String encryptedPassword = passwordEncryptor.encryptPassword(password); return encryptedPassword; } public static boolean checkPassword(String plainPassword, String encryptedPassword)
5960616263646566676869
public void testPasswordEncryptionUsingBasicEncryptor() throws Exception { // Declare a basic encryptor BasicPasswordEncryptor bpe = new BasicPasswordEncryptor(); // "Encrypt password", is not an real encryption because "Encryptor" // generate a digest. by default the MD5 algorithm is used String encryptedPassword = bpe.encryptPassword(TEXT_TO_ENCRYPT); System.out.printf("testPasswordEncryptionUsingBasicEncryptor : '%s' become '%s'\n", TEXT_TO_ENCRYPT, encryptedPassword); // Valid "encrypted" password Assert.assertTrue(bpe.checkPassword(TEXT_TO_ENCRYPT, encryptedPassword)); }
3334353637383940414243
String usuarioSkype)throws Exception{ Usuario usu = new Usuario(); usu.setNombreUsuario(nombre); BasicPasswordEncryptor encriptador = new BasicPasswordEncryptor (); String passEncriptada = encriptador.encryptPassword(password); usu.setPassword(passEncriptada); usu.setUsuariosSkype(usuarioSkype); usu.setFechaRegistro(new Date()); usu.setEmail(email); PermisosUsuarioDAO permUsuDAO = new PermisosUsuarioDAO();
337338339340341342343344345346347
userLogDao.logResetPassword(user, moderator); } private String setPassword(User user, String password) { PasswordEncryptor encryptor = new BasicPasswordEncryptor(); String encryptedPassword = encryptor.encryptPassword(password); jdbcTemplate.update("UPDATE users SET passwd=?, lostpwd = 'epoch' WHERE id=?", encryptedPassword, user.getId()); return password;
514515516517518519520521522523524
"(id, name, nick, passwd, url, email, town, score, max_score,regdate) " + "VALUES (?,?,?,?,?,?,?,45,45,current_timestamp)", userid, name, nick, encryptor.encryptPassword(password), url==null?null: URLUtil.fixURL(url), mail.getAddress(), town );
6364656667686970717273
BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor(); userUpdate = usersRepository.findOne(id); if (userUpdate == null || !userUpdate.getEnabled()){ return false; } else { userUpdate.setPassword(passwordEncryptor.encryptPassword(password)); save(userUpdate.getId(), userUpdate); } return true; }
3738394041424344454647
UsersService usersService = ctx.getBean("usersService", UsersService.class); PreferencesService preferenceService = ctx.getBean("preferencesService", PreferencesService.class); BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor(); String encryptedPassword = passwordEncryptor.encryptPassword(request.getParameter("pw")); if(usersService.findById(request.getParameter("un")) != null) { request.setAttribute("registrationMessage", "Username is already taken please regiser with another user name."); String url = "/Register.jsp"; RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);