1. 程式人生 > >使用者註冊 及 密碼校驗 BCrypt

使用者註冊 及 密碼校驗 BCrypt

使用者註冊的加密方式 除了MD5 還有更安全的方式 用 BCrypt

前提:

	<dependency>
		<groupId>at.favre.lib</groupId>
		<artifactId>bcrypt</artifactId>
		<version>0.8.0</version>
	</dependency>

使用:
 

		// 生成密碼
        String bcryptHashString = BCrypt.withDefaults().hashToString(10, "123456".toCharArray());

		System.out.println(bcryptHashString);

        // 校驗密碼
		BCrypt.Result result = BCrypt.verifyer().verify("123456".toCharArray(), bcryptHashString);

		System.out.println(result.verified);