docs/api/exposed-crypt/org.jetbrains.exposed.v1.crypt/hashed.html
fun Column<String>.hashed(hasher: Hasher = BCryptHasher()): Column<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)
Content copied to clipboard
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") }
Content copied to clipboard
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.
A new column holding Hashed values.
hasher
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.
@JvmName(name = "hashedNullable")
fun Column<String?>.hashed(hasher: Hasher = BCryptHasher()): Column<Hashed?>
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) == true
Content copied to clipboard
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 recoveryCode = text("recovery_code").nullable().hashed()}Users.insert { it[recoveryCode] = Users.recoveryCode.hash("r3covery") }
Content copied to clipboard
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.
A new nullable column holding Hashed values.
hasher
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.
Generated by Dokka © 2026 Copyright