org.apache.shiro.crypto.hash.Sha512Hash Java Examples
The following examples show how to use
org.apache.shiro.crypto.hash.Sha512Hash.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Helpers.java From jqm with Apache License 2.0 | 6 votes |
/** * Creates a new user if does not exist. If it exists, it is unlocked and roles are reset (password is untouched). * * @param cnx * @param login * @param password * the raw password. it will be hashed. * @param description * @param roles */ static void createUserIfMissing(DbConn cnx, String login, String password, String description, String... roles) { try { int userId = cnx.runSelectSingle("user_select_id_by_key", Integer.class, login); cnx.runUpdate("user_update_enable_by_id", userId); RUser.set_roles(cnx, userId, roles); } catch (NoResultException e) { String saltS = null; String hash = null; if (null != password && !"".equals(password)) { ByteSource salt = new SecureRandomNumberGenerator().nextBytes(); hash = new Sha512Hash(password, salt, 100000).toHex(); saltS = salt.toHex(); } RUser.create(cnx, login, hash, saltS, roles); } }
Example #2
Source File: PasswordUtil.java From ueboot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 对密码进行sha512模式加密 * @param userName 用户名(用来做salt) * @param password 原始密码 * @return 加密后的密码 */ public static String sha512(String userName,String password) { //以账号作为盐值 ByteSource salt = ByteSource.Util.bytes(userName); //加密2次 int hashIterations = 2; Sha512Hash hash = new Sha512Hash(password,salt,hashIterations); return hash.toString(); }
Example #3
Source File: PasswordHelper.java From init-spring with Apache License 2.0 | 5 votes |
public static User generatePassword(User user){ byte[] passwordSalt = UUID.randomUUID().toString().getBytes(); user.setPasswordSalt(passwordSalt); String passwordHash = new Sha512Hash(user.getPassword(), user.getName() + new String(passwordSalt), 99).toString(); user.setPasswordHash(passwordHash); return user; }
Example #4
Source File: MetaService.java From jqm with Apache License 2.0 | 5 votes |
public static void changeUserPassword(DbConn cnx, int userId, String newPassword) { ByteSource salt = new SecureRandomNumberGenerator().nextBytes(); String hash = new Sha512Hash(newPassword, salt, 100000).toHex(); QueryResult qr = cnx.runUpdate("user_update_password_by_id", hash, salt.toHex(), userId); if (qr.nbUpdated == 0) { throw new JqmAdminApiUserException("user with this ID does not exist"); } }
Example #5
Source File: CreationTools.java From jqm with Apache License 2.0 | 5 votes |
public static void createUser(DbConn cnx, String login, String password, RRole... roles) { ByteSource salt = new SecureRandomNumberGenerator().nextBytes(); String[] rr = new String[roles.length]; for (int i = 0; i < roles.length; i++) { rr[i] = roles[i].getName(); } RUser.create(cnx, login, new Sha512Hash(password, salt, 100000).toHex(), salt.toHex(), rr); }
Example #6
Source File: InitSQLData.java From init-spring with Apache License 2.0 | 4 votes |
@Override public void contextInitialized(ServletContextEvent sce) { WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); PersonRepository personRepository = webApplicationContext.getBean(PersonRepository.class); personRepository.deleteAll(); List<Person> personList = new ArrayList<>(); for (int i = 0; i < 100; i++) { String chars = "abcdefghijklmnopqrstuvwxyz"; String name = String.valueOf(chars.charAt((int) (Math.random() * 26))); Person person = new Person(); person.setName(name); person.setAge((i % 100) + 1); personList.add(person); } personRepository.save(personList); UserRepository userRepository = webApplicationContext.getBean(UserRepository.class); userRepository.deleteAll(); User user = new User(); user.setName("[email protected]"); byte[] passwordSalt = UUID.randomUUID().toString().getBytes(); user.setPasswordSalt(passwordSalt); user.setPassword("123"); String passwordHash = new Sha512Hash(user.getPassword(), user.getName() + new String(passwordSalt), 99) .toString(); user.setPasswordHash(passwordHash); RoleRepository roleRepository = webApplicationContext.getBean(RoleRepository.class); roleRepository.deleteAll(); Set<Role> roleSet = new HashSet<>(); Role role = new Role(); role.setName("admin"); role.setDescription("管理员"); List<String> permissisonList = new ArrayList<>(); permissisonList.add("user:view"); permissisonList.add("role:view"); role.setPermissions(permissisonList); roleSet.add(roleRepository.save(role)); user.setRoles(roleSet); userRepository.save(user); }