hashed
Transforms this character column into one that stores one-way hashed values, using the provided hasher.
val passwordHasher = BCryptHasher()
object Users : IntIdTable() {
val password = text("password").hashed(passwordHasher)
}
Users.insert { it[password] = passwordHasher.hash("s3cret") }
val user = Users.selectAll().where { Users.id eq id }.single()
val granted = user[Users.password].matches(submittedPassword)Using the default argument for hasher requires calling hash() directly on the column, as that is the only way to reach the underlying default Hasher implementation:
object Users : IntIdTable() {
val password = text("password").hashed()
}
Users.insert { it[password] = Users.password.hash("s3cret") }hash() works whichever way the column was declared, and is worth preferring even when a hasher is at hand: it always hashes with the one the column verifies with, which a separately held Hasher is not guaranteed to be.
A stored value can only be verified by the algorithm that produced it, so changing hasher on a column that already holds data stops the values written before the change from matching.
Return
A new column holding Hashed values.
Parameters
Hasher responsible for hashing values and for verifying them against stored hashes. Defaults to BCryptHasher, the provided algorithm that needs nothing beyond exposed-crypt itself.
Transforms this nullable character column into one that stores one-way hashed values, using the provided hasher, and leaving null values untouched.
val recoveryCodeHasher = BCryptHasher()
object Users : IntIdTable() {
val recoveryCode = text("recovery_code").nullable().hashed(recoveryCodeHasher)
}
Users.insert { it[recoveryCode] = recoveryCodeHasher.hash("r3covery") }
val user = Users.selectAll().where { Users.id eq id }.single()
val granted = user[Users.recoveryCode]?.matches(submittedCode) == trueUsing the default argument for hasher requires calling hash() directly on the column, as that is the only way to reach the underlying default Hasher implementation:
object Users : IntIdTable() {
val recoveryCode = text("recovery_code").nullable().hashed()
}
Users.insert { it[recoveryCode] = Users.recoveryCode.hash("r3covery") }hash() works whichever way the column was declared, and is worth preferring even when a hasher is at hand: it always hashes with the one the column verifies with, which a separately held Hasher is not guaranteed to be.
A stored value can only be verified by the algorithm that produced it, so changing hasher on a column that already holds data stops the values written before the change from matching.
Return
A new nullable column holding Hashed values.
Parameters
Hasher responsible for hashing values and for verifying them against stored hashes. Defaults to BCryptHasher, the provided algorithm that needs nothing beyond exposed-crypt itself.