시큐리티 설정
유저 API - 로그인, 회원가입, 계정정보 추가
This commit is contained in:
34
src/main/kotlin/kr/co/vividnext/sodalive/utils/Utils.kt
Normal file
34
src/main/kotlin/kr/co/vividnext/sodalive/utils/Utils.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package kr.co.vividnext.sodalive.utils
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.SecureRandom
|
||||
import java.util.Base64
|
||||
import java.util.Random
|
||||
import java.util.UUID
|
||||
|
||||
fun generatePassword(length: Int): String {
|
||||
val characterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()1234567890"
|
||||
val random = SecureRandom()
|
||||
val password = StringBuilder()
|
||||
|
||||
for (i in 0 until length) {
|
||||
val rIndex = random.nextInt(characterSet.length)
|
||||
password.append(characterSet[rIndex])
|
||||
}
|
||||
|
||||
return password.toString()
|
||||
}
|
||||
|
||||
fun generateFileName(prefix: String = ""): String {
|
||||
val timestamp = System.currentTimeMillis()
|
||||
val random = Random().nextInt(10000)
|
||||
val uuid = UUID.randomUUID().toString()
|
||||
|
||||
return if (prefix.isBlank()) {
|
||||
Base64
|
||||
.getUrlEncoder()
|
||||
.encodeToString("$uuid-$random-$timestamp".toByteArray(StandardCharsets.UTF_8))
|
||||
} else {
|
||||
"$prefix-$uuid-$random-$timestamp"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user