ThatCoders revised this gist . Go to revision
1 file changed, 12 insertions
PassUtil.kt
@@ -18,5 +18,17 @@ class PassUtil private constructor() { | |||
18 | 18 | fun encode(password: String): String { | |
19 | 19 | return encoder.encode(password) | |
20 | 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 | + | } | |
21 | 33 | } | |
22 | 34 | } |
ThatCoders revised this gist . Go to revision
1 file changed, 22 insertions
PassUtil.kt(file created)
@@ -0,0 +1,22 @@ | |||
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 | + | } |