public static void main(String[] args) {
   Md5PasswordEncoder md5 = new Md5PasswordEncoder();
   String passwordString = md5.encodePassword("123", "username");
   System.out.println(passwordString);
   boolean b = md5.isPasswordValid("1ee21fff6208ea4aae8d7f52e6f5d06d", "123", "name");
   System.out.println(b);
 }
Пример #2
0
  @Override
  public Authentication attemptAuthentication(
      HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    if (!request.getMethod().equals("POST")) {
      throw new AuthenticationServiceException(
          "Authentication method not supported: " + request.getMethod());
    }

    String username = obtainUsername(request);
    String password = obtainPassword(request);

    // Validates username and password
    username = username.trim();

    User user = UserUtil.getUser(username);
    Md5PasswordEncoder encoder = new Md5PasswordEncoder();
    password = encoder.encodePassword(password, AuthenticationFilter.SALT);
    if (user == null || !user.getPassword().equals(password)) {
      throw new AuthenticationServiceException("password or username is notEquals");
    }

    UsernamePasswordAuthenticationToken authRequest =
        new UsernamePasswordAuthenticationToken(username, password);

    setDetails(request, authRequest);

    // return authRequest;
    return this.getAuthenticationManager().authenticate(authRequest);
  }
  @RequestMapping(value = "/newtransemployee/op1", method = RequestMethod.POST)
  public ModelAndView newTransEmployeePost(
      @ModelAttribute @Valid User user,
      BindingResult result,
      final RedirectAttributes attributes,
      Principal principal)
      throws BankDeactivatedException {
    System.out.println("INSIDE trans manager post Controller for new employee .............");
    OneTimePassword otp = new OneTimePassword();
    String message;
    ModelAndView mav = new ModelAndView();
    try {
      System.out.println("\n Inside Employee signup post controller");
      if (result.hasErrors()) {
        // return new ModelAndView("hr/newhremployee", "signupemployee",employee);
        // return savedMav;
        // return new ModelAndView("hr/manager/manager","signupemployee",user);
        message = "Validation Errors observed.Please go back and fill valid information";
        mav.addObject("message", message);
        mav.setViewName("signup/saveData");
        return mav;
        // return new ModelAndView("signup/saveData", "signupemployee",user);
      }

      mav.setViewName("signup/saveData");
      message =
          "Congratulations..!! Your request has been approved. Please ask the user to check the email and login";
      user.setDepartment("TM");
      user.setRole("ROLE_TRANSACTION_EMPLOYEE");
      user.setCreatedBy(principal.getName());
      Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
      String password = otp.getPassword();
      String hashedPassword = passwordEncoder.encodePassword(otp.getPassword(), null);

      transManager.insertValidUser(user, hashedPassword, principal.getName());
      enManager.sendPassword(user, password);
      mav.addObject("message", message);
      mav.addObject("username", principal.getName());
      return mav;
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      if (e instanceof com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException) {
        message = "Username already Exists.Choose a different username";
        mav.addObject("message", message);
        mav.setViewName("signup/saveData");
        mav.addObject("username", principal.getName());
        return mav;
      } else if (e instanceof BankDeactivatedException) {
        throw new BankDeactivatedException(e.getMessage());
      } else {
        message = "Error in saving your data.Please try again";
        mav.addObject("message", message);
        mav.setViewName("signup/saveData");
        mav.addObject("username", principal.getName());
        return mav;
      }
    }
  }
 @Override
 public int updateByPrimaryKey(StockUser record) {
   if (StringUtils.isNotBlank(record.getPassword())) {
     Md5PasswordEncoder md5encode = new Md5PasswordEncoder();
     record.setPassword(md5encode.encodePassword(record.getPassword(), record.getUsername()));
   }
   return stockUserMapper.updateByPrimaryKeySelective(record);
 }
Пример #5
0
  @Override
  public boolean updateAdmin(RegisterAdminPara registerAdminPara) throws Exception {

    int intResult = 0;

    Map<String, Object> mapRegisterAdmin = new HashMap<String, Object>();
    mapRegisterAdmin.put("adminId", registerAdminPara.getAdminId());
    mapRegisterAdmin.put("gameId", registerAdminPara.getGameId());
    mapRegisterAdmin.put(
        "adminPwd", passwordEncoder.encodePassword(registerAdminPara.getAdminPwd(), null));
    mapRegisterAdmin.put("adminName", registerAdminPara.getAdminName());
    mapRegisterAdmin.put("adminMail", registerAdminPara.getAdminMail());
    mapRegisterAdmin.put("adminStatusFlag", registerAdminPara.getAdminStatusFlag());

    try {
      intResult = masterAdminDao.getMapper(MasterAdminDao.class).updateAdmin(mapRegisterAdmin);
    } catch (Exception e) {
      logger.error("Exception error", e);
      return false;
    }
    if (intResult < 1) {
      logger.error(
          "UpdateAdmin error, adminId={}, gameId={}",
          registerAdminPara.getAdminId(),
          registerAdminPara.getGameId());
      return false;
    }

    return true;
  }
Пример #6
0
 public Integer savePasswordChanged(ChangePassword cp) {
   Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
   cp.setPassword(passwordEncoder.encodePassword(cp.getPassword(), null));
   cp.setNewpassword(passwordEncoder.encodePassword(cp.getNewpassword(), null));
   Query query =
       new Query(Criteria.where("id").is(cp.getUserid()).and("password").is(cp.getPassword()));
   Users usr = mongoTemplate.findOne(query, Users.class);
   if (null != usr) {
     usr.setPassword(cp.getNewpassword());
     usr.setModifiedDate(new Date());
     userRepository.save(usr);
     return 1;
   } else {
     return 0;
   }
 }
Пример #7
0
  public int resetAndSavePassword(String email) {
    Users user = userRepository.findByEmail(email);
    if (null == user) {
      return 0;
    } else {

      Random randomGenerator = new Random();
      int randomInt = randomGenerator.nextInt(100000);

      Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
      user.setPassword(passwordEncoder.encodePassword(randomInt + "", null));

      userRepository.save(user);
      return randomInt;
    }
  }
Пример #8
0
 public String buildUidFromHttpGetRequest() throws NoSuchAlgorithmException {
   HttpServletRequest request = this.getRequest();
   String url = request.getServletPath();
   String query = request.getQueryString();
   if (StringUtils.isNotEmpty(query)) {
     url = url + "?" + query;
   }
   return md5PasswordEncoder.encodePassword(url, null);
 }
Пример #9
0
 @Override
 public User getUser(String username, String password) {
   try {
     Map<String, Object> params = new HashMap<String, Object>();
     params.put("username", username);
     params.put("password", md5.encodePassword(password, username));
     User admin = (User) this.sqlMapClientTemplate.queryForObject("tbl_user.getUser", params);
     return admin;
   } catch (Exception e) {
     throw new RpcException("查询用户出错", e);
   }
 }
Пример #10
0
  public String save(Users users) {
    // System.out.println("users.getjoinedid:::: "+users.getJoinedid());
    if (StringUtils.isNotEmpty(users.getId())) {
      Users userstmp = getUserForEdit(users.getId());
      userstmp.setColorTheme(users.getColorTheme());
      userstmp.setName(users.getName());
      userstmp.setEmail(users.getEmail());
      userstmp.setModifiedDate(new Date());
      users = userstmp;
    } else {
      if (userRepository.findByUsername(users.getUsername()) != null) {
        return "username";
      } else if (userRepository.findByEmail(users.getEmail()) != null) {
        return "email";
      }
      Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
      users.setPassword(passwordEncoder.encodePassword(users.getPassword(), null));
      users.setCreatedDate(new Date());
      users.setModifiedDate(new Date());
    }

    userRepository.save(users);
    return "save";
  }
 /**
  * Encrypt password ,if original password is empty,
  *
  * @param originalPassword Original password
  * @return Encrypted password
  */
 public static String encryptPassword(String originalPassword) {
   Md5PasswordEncoder md5PasswordEncoder = new Md5PasswordEncoder();
   return md5PasswordEncoder.encodePassword(originalPassword, null);
 }
Пример #12
0
 /**
  * Method for hsahing string with md5.
  *
  * @return
  */
 public String getMd5Pass(String password) {
   return encoder.encodePassword(password, null);
 }
Пример #13
0
 /**
  * Compare passwords
  *
  * @param rawPassword clear-text password
  * @param encodedPassword encoded password
  * @return whether passwords match
  */
 @Override
 public boolean matches(CharSequence rawPassword, String encodedPassword) {
   return passwordEncoder.encodePassword(rawPassword.toString(), null).equals(encodedPassword);
 }
Пример #14
0
 /**
  * MD5 encoding
  *
  * @param rawPassword password
  * @return encoded password
  */
 @Override
 public String encode(CharSequence rawPassword) {
   return passwordEncoder.encodePassword(rawPassword.toString(), null);
 }
Пример #15
0
 private String password(String password) {
   Md5PasswordEncoder encoder = new Md5PasswordEncoder();
   return encoder.encodePassword(password, null);
 }
 /**
  * Encripta a senha.
  *
  * @param senha a senha ser encriptada
  * @return a senha encriptada
  */
 public static String encriptarSenha(String senha) {
   return encriptador.encodePassword(senha, null);
 }
Пример #17
0
 /**
  * Method for hashing (md5) with salt for user password
  *
  * @return
  */
 public String getMd5SaltPass(String salt, String password) {
   salt = salt.substring(2, 4);
   return encoder.encodePassword(password, salt);
 }
Пример #18
0
 public static void main(String[] args) {
   Md5PasswordEncoder md5 = new Md5PasswordEncoder();
   String pwd = md5.encodePassword("boss", "boss");
   System.out.println(pwd);
 }