Files
SimpleNotes/domain/src/main/kotlin/security/PasswordHash.kt
T
2020-08-13 19:39:41 +02:00

15 lines
541 B
Kotlin

package be.simplenotes.domain.security
import org.mindrot.jbcrypt.BCrypt
internal interface PasswordHash {
fun crypt(password: String): String
fun verify(password: String, hashedPassword: String): Boolean
}
internal class BcryptPasswordHash(test: Boolean = false) : PasswordHash {
private val rounds = if (test) 4 else 10
override fun crypt(password: String) = BCrypt.hashpw(password, BCrypt.gensalt(rounds))!!
override fun verify(password: String, hashedPassword: String) = BCrypt.checkpw(password, hashedPassword)
}