PassUtil.kt
· 920 B · Kotlin
Raw
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
/**
* 密码工具类
* @author ThatCoder
*/
class PassUtil private constructor() {
companion object {
private val encoder = BCryptPasswordEncoder()
/**
* 密码加密
* @author ThatCoder
* @param password 密码
* @return 加密后的密码 length:60
*/
@JvmStatic
fun encode(password: String): String {
return encoder.encode(password)
}
/**
* 验证密码
* @author ThatCoder
* @param rawPassword 用户输入的密码
* @param encodedPassword 存储的加密密码
* @return 密码是否匹配
*/
@JvmStatic
fun matches(rawPassword: String, encodedPassword: String): Boolean {
return encoder.matches(rawPassword, encodedPassword)
}
}
}
1 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder |
2 | |
3 | /** |
4 | * 密码工具类 |
5 | * @author ThatCoder |
6 | */ |
7 | class PassUtil private constructor() { |
8 | companion object { |
9 | private val encoder = BCryptPasswordEncoder() |
10 | |
11 | /** |
12 | * 密码加密 |
13 | * @author ThatCoder |
14 | * @param password 密码 |
15 | * @return 加密后的密码 length:60 |
16 | */ |
17 | @JvmStatic |
18 | fun encode(password: String): String { |
19 | return encoder.encode(password) |
20 | } |
21 | |
22 | /** |
23 | * 验证密码 |
24 | * @author ThatCoder |
25 | * @param rawPassword 用户输入的密码 |
26 | * @param encodedPassword 存储的加密密码 |
27 | * @return 密码是否匹配 |
28 | */ |
29 | @JvmStatic |
30 | fun matches(rawPassword: String, encodedPassword: String): Boolean { |
31 | return encoder.matches(rawPassword, encodedPassword) |
32 | } |
33 | } |
34 | } |