当前位置: 首页>>代码示例>>Java>>正文


Java BCrypt.hashpw方法代码示例

本文整理汇总了Java中org.mindrot.jbcrypt.BCrypt.hashpw方法的典型用法代码示例。如果您正苦于以下问题:Java BCrypt.hashpw方法的具体用法?Java BCrypt.hashpw怎么用?Java BCrypt.hashpw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mindrot.jbcrypt.BCrypt的用法示例。


在下文中一共展示了BCrypt.hashpw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: userSignUp

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
public Credentials userSignUp(Credentials credentials) throws DAOException{
    if (getUserByEmail(dao,credentials.getEmailAddress())!=null){
        throw new DAOException(HttpStatus.SC_CONFLICT,"User Already Exists");
    }
    ServerCredentials toSave = new ServerCredentials(credentials);

    toSave.decryptPassword(keyManager.getPrivateKey()); //decrypt the password
    String de = toSave.getPassword();
    String ha = BCrypt.hashpw(de, BCrypt.gensalt(10));

    toSave.setOwnerId(dao.count(Credentials.class.getName()) + 1);
    toSave.setPassword(ha); //hash the password for storage
    toSave.setAuthToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), toSave));
    toSave.setRecoveryToken(AuthTokenUtils.getNewToken(keyManager.getSymmetricKey(), toSave));

    dao.save(toSave);

    return toSave;
}
 
开发者ID:williamwebb,项目名称:divide,代码行数:20,代码来源:AuthServerLogic.java

示例2: setPassword

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Override
public void setPassword(String password) {
	if (((getEncryption() == 0) || (!password.equalsIgnoreCase(getPassword()))) && (_um != null)) {
		String pass;
		switch (_um.getPasscrypt()) {
			case 1: pass = Encrypt(password,"MD2"); setEncryption(1); break;
			case 2: pass = Encrypt(password,"MD5"); setEncryption(2); break;
			case 3: pass = Encrypt(password,"SHA-1"); setEncryption(3); break;
			case 4: pass = Encrypt(password,"SHA-256"); setEncryption(4); break;
			case 5: pass = Encrypt(password,"SHA-384"); setEncryption(5); break;
			case 6: pass = Encrypt(password,"SHA-512"); setEncryption(6); break;
			case 7: pass = BCrypt.hashpw(password, BCrypt.gensalt(_workload)); setEncryption(7); break;
			default: pass = password; setEncryption(0); break;
		}

		if (pass != null) {
			if (pass.length() < 2) {
				logger.debug("Failed To Set Password, Length Too Short");
			} else {
				super.setPassword(pass);
			}
		}
	} else {
		super.setPassword(password);
	}
}
 
开发者ID:drftpd-ng,项目名称:drftpd3,代码行数:27,代码来源:EncryptedBeanUser.java

示例3: respondWith200_whenCreateAToken_ifProvidedBothAccountIdAndDescription

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Test
public void respondWith200_whenCreateAToken_ifProvidedBothAccountIdAndDescription() throws Exception {
    String newToken = createTokenFor(validTokenPayload)
            .statusCode(200)
            .body("token", is(notNullValue()))
            .extract().path("token");

    int apiKeyHashSize = 32;
    String tokenApiKey = newToken.substring(0, newToken.length() - apiKeyHashSize);
    String hashedToken = BCrypt.hashpw(tokenApiKey, SALT);

    Optional<String> newTokenDescription = app.getDatabaseHelper().lookupColumnForTokenTable("description", TOKEN_HASH_COLUMN, hashedToken);

    assertThat(newTokenDescription.get(), equalTo(TOKEN_DESCRIPTION));

    Optional<String> newTokenAccountId = app.getDatabaseHelper().lookupColumnForTokenTable("account_id", TOKEN_HASH_COLUMN, hashedToken);
    assertThat(newTokenAccountId.get(), equalTo(ACCOUNT_ID));

    Optional<String> newCreatedByEmail = app.getDatabaseHelper().lookupColumnForTokenTable("created_by", TOKEN_HASH_COLUMN, hashedToken);
    assertThat(newCreatedByEmail.get(), equalTo(USER_EMAIL));

    Optional<String> newTokenType = app.getDatabaseHelper().lookupColumnForTokenTable("token_type", TOKEN_HASH_COLUMN, hashedToken);
    assertThat(newTokenType.get(), equalTo(CARD.toString()));
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:25,代码来源:PublicAuthResourceITest.java

示例4: createMagicianFromForm

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
/**
 * Create a new Magician object from EditUserFormData.  Add it to the database and return the newly created
 * Magician.
 *
 * @param editUserFormData The source of data for the Magician.
 * @return A fully populated Magician object that's just been persisted in the database.
 */
public static Magician createMagicianFromForm(EditUserFormData editUserFormData) {
  Magician magician = null;
  MagicianType magicianType = MagicianType.getMagicianType(editUserFormData.magicianType);

  if (editUserFormData.id == 0) {
    magician = new Magician(
        editUserFormData.firstName
        , editUserFormData.lastName
        , editUserFormData.email
        , magicianType
        , BCrypt.hashpw(editUserFormData.password, BCrypt.gensalt(12)));
  }
  else {
    magician = Magician.find().byId(editUserFormData.id);
    magician.setFirstName(editUserFormData.firstName);
    magician.setLastName(editUserFormData.lastName);
    magician.setEmail(editUserFormData.email);
    magician.setMagicianType(magicianType);
    magician.setPassword(BCrypt.hashpw(editUserFormData.password, BCrypt.gensalt(12)));
  }

  magician.save();
  return magician;
}
 
开发者ID:PlayWithMagic,项目名称:PlayWithMagic.org,代码行数:32,代码来源:Magician.java

示例5: testGensaltInt

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
/**
 * Test method for 'BCrypt.gensalt(int)'
 */
public void testGensaltInt() {
	System.out.print("BCrypt.gensalt(log_rounds):");
	for (int i = 4; i <= 12; i++) {
		System.out.print(" " + Integer.toString(i) + ":");
		for (int j = 0; j < test_vectors.length; j += 4) {
			String plain = test_vectors[j][0];
			String salt = BCrypt.gensalt(i);
			String hashed1 = BCrypt.hashpw(plain, salt);
			String hashed2 = BCrypt.hashpw(plain, hashed1);
			assertEquals(hashed1, hashed2);
			System.out.print(".");
		}
	}
	System.out.println("");
}
 
开发者ID:svenkubiak,项目名称:jBCrypt,代码行数:19,代码来源:TestBCrypt.java

示例6: setup

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Produces(MediaType.APPLICATION_JSON)
    @GET
    @Path("/setup")
    public Response setup() throws Exception{
//        logger.info("setup");
//        Credentials user = TestUtils.getTestUser();
//        user = new ServerCredentials(user);
//        user.setPassword(BCrypt.hashpw(user.getPassword(), BCrypt.gensalt(10)));

        ServerCredentials toSave = new ServerCredentials(TestUtils.getTestUser());

//        String en = toSave.getPassword();
//        toSave.decryptPassword(keyManager.getPrivateKey()); //decrypt the password
//        String de = toSave.getPassword();
        String ha = BCrypt.hashpw(toSave.getPassword(), BCrypt.gensalt(10));
        toSave.setPassword(ha); //hash the password for storage
        toSave.setAuthToken(AuthTokenUtils.getNewToken(securityManager.getSymmetricKey(), toSave));
        toSave.setRecoveryToken(AuthTokenUtils.getNewToken(securityManager.getSymmetricKey(), toSave));
        toSave.setOwnerId(dao.count(Credentials.class.getName()) + 1);

        dao.save(toSave);
        return Response.ok().entity(toSave).build();
    }
 
开发者ID:williamwebb,项目名称:divide,代码行数:24,代码来源:TestEndpoint.java

示例7: hashPassword

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
/**
 * Hash password.
 * 
 * @param username
 *            not null
 * @param password
 *            not null
 * @return not null
 */
private static String hashPassword(String username, String password, String alg) {
    String newPass;
    if (alg == null || alg.equals("MD5")) {
        newPass = DigestUtils.md5Hex(password);
    } else if (alg.equals("NONE")) {
        newPass = "password";
    } else if (alg.equals("BCRYPT")) {
        newPass = BCrypt.hashpw(password, BCrypt.gensalt());
    } else if (alg.equals("BCRYPT_SHA-512")) {
        newPass = DigestUtils.sha512Hex(BCrypt.hashpw(password, BCrypt.gensalt()));
    } else if (alg.equals("SHA-256")) {
        newPass = DigestUtils.sha256Hex(password);
    } else if (alg.equals("SHA-512")) {
        newPass = DigestUtils.sha512Hex(password);
    } else {
        newPass = DigestUtils.shaHex(password);
    }
    return newPass;
}
 
开发者ID:twachan,项目名称:James,代码行数:29,代码来源:JPAUser.java

示例8: register

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
public Resolution register() {
	if (WebContainerProperties.INSTANCE.getSystemDisabledDate().before(new Date())) {
		return new RedirectResolution(LandingActionBean.class);
	}
	String hashed = BCrypt.hashpw(password, BCrypt.gensalt());
	User user = new User(HtmlEscapers.htmlEscaper().escape(getUsername()), hashed, getEmail());
	user.setMainJavaScript(DefaultCode.INSTANCE.getDefaultCode());
	user.setCreatedDate(new Date());
	user.setLastLoginDate(new Date());
	if (WebContainerProperties.INSTANCE.isEmailVerificationEnabled()) {
		user.setActive(false);
		user.setEmailConfirmed(false);
		userDao.add(user);
		EmailService.INSTANCE.sendNewAccount(user.getEmail(), user.getId(), user.getUsername());
		EmailService.INSTANCE.informAdminRegister(user.getUsername(), user.getEmail());
		return new ForwardResolution(POST);
	} else {
		user.setActive(true);
		user.setEmailConfirmed(true);
		user.setLastLoginDate(new Date());
		userDao.add(user);
		getContext().getRequest().getSession(true).setAttribute("userid", user.getId());
		return new RedirectResolution(PortalActionBean.class);
	}		
}
 
开发者ID:oglimmer,项目名称:cyc,代码行数:26,代码来源:RegisterActionBean.java

示例9: hashPassword

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Override
public String hashPassword(String password) {
    verifyPasswordInput(password);

    String salt = BCrypt.gensalt(LOG_ROUNDS, new SecureRandom());
    return BCrypt.hashpw(password, salt);
}
 
开发者ID:erikns,项目名称:webpoll,代码行数:8,代码来源:SecurePasswordHasher.java

示例10: authenticate

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
public static boolean authenticate(String username, String password) {
    if (username == null || password == null) {
        return false;
    }
    User user = userDao.getUserByUsername(username);
    if (user == null) {
        return false;
    }
    String hashedPassword = BCrypt.hashpw(password, user.salt);
    return hashedPassword.equals(user.hashedPassword);
}
 
开发者ID:tipsy,项目名称:javalin-website-example,代码行数:12,代码来源:UserController.java

示例11: setPassword

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
public static void setPassword(String username, String oldPassword, String newPassword) {
    if (authenticate(username, oldPassword)) {
        String newSalt = BCrypt.gensalt();
        String newHashedPassword = BCrypt.hashpw(newSalt, newPassword);
        // Update the user salt and password
    }
}
 
开发者ID:tipsy,项目名称:javalin-website-example,代码行数:8,代码来源:UserController.java

示例12: authenticate

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Override
public boolean authenticate(String username, String password) {
    if (username.isEmpty() || password.isEmpty()) {
        return false;
    }
    Optional<User> user = userDao.getUserByUsername(username);
    if (!user.isPresent()) {
        return false;
    }
    String hashedPassword = BCrypt.hashpw(password, user.get().getSalt());
    return hashedPassword.equals(user.get().getHashedPassword());
}
 
开发者ID:oleg-vasiliev,项目名称:sparkjava-boilerplate,代码行数:13,代码来源:UserServiceImpl.java

示例13: authenticateAndGet

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Override
public Optional<User> authenticateAndGet(String username, String password) {
    if (username.isEmpty() || password.isEmpty()) {
        return Optional.empty();
    }
    Optional<User> user = userDao.getUserByUsername(username);
    if (user.isPresent()) {
        String hashedPassword = BCrypt.hashpw(password, user.get().getSalt());
        return hashedPassword.equals(user.get().getHashedPassword()) ? user : Optional.empty();
    } else
        return Optional.empty();
}
 
开发者ID:oleg-vasiliev,项目名称:sparkjava-boilerplate,代码行数:13,代码来源:UserServiceImpl.java

示例14: setPassword

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Override
public boolean setPassword(String username, String oldPassword, String newPassword) {
    Optional<User> userOptional = authenticateAndGet(username, oldPassword);
    if (userOptional.isPresent()) {
        String newSalt = BCrypt.gensalt();
        String newHashedPassword = BCrypt.hashpw(newPassword, newSalt);
        User user = userOptional.get();
        user.setSalt(newSalt);
        user.setHashedPassword(newHashedPassword);
        userDao.saveUser(user);
        return true;
    } else {
        return false;
    }
}
 
开发者ID:oleg-vasiliev,项目名称:sparkjava-boilerplate,代码行数:16,代码来源:UserServiceImpl.java

示例15: hash

import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
@Override
public String hash(CliArguments arguments) {
    final String salt = BCrypt.gensalt(arguments.cost());

    final String hashedPasswd = BCrypt.hashpw(arguments.password(), salt);

    return format("{0}={1}", arguments.username(), hashedPasswd);
}
 
开发者ID:gocd,项目名称:gocd-filebased-authentication-plugin,代码行数:9,代码来源:BCryptProvider.java


注:本文中的org.mindrot.jbcrypt.BCrypt.hashpw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。