Back to Exposed

hash

docs/api/exposed-crypt/org.jetbrains.exposed.v1.crypt/hash.html

1.5.02.4 KB
Original Source

hash

fun Column<Hashed>.hash(plainText: String): Hashed

Hashes plainText with the Hasher this column was declared with, ready to be stored in it.

Using this rather than a separately held Hasher rules out hashing a value with one algorithm and storing it in a column that verifies with another, which the column cannot detect and which makes every later Hashed.matches fail. It is the only way to hash for a column declared without an explicit hasher:

kotlin
object Users : IntIdTable() { val password = text("password").hashed()}Users.insert { it[password] = Users.password.hash("s3cret") }

Content copied to clipboard

Return

The Hashed result of applying this column's Hasher to plainText.

Parameters

plainText

Value to hash


@JvmName(name = "hashNullable")

fun Column<Hashed?>.hash(plainText: String): Hashed

Hashes plainText with the Hasher this nullable column was declared with, ready to be stored in it.

Using this rather than a separately held Hasher rules out hashing a value with one algorithm and storing it in a column that verifies with another, which the column cannot detect and which makes every later Hashed.matches fail. It is the only way to hash for a column declared without an explicit hasher:

kotlin
object Users : IntIdTable() { val recoveryCode = text("recovery_code").nullable().hashed()}Users.insert { it[recoveryCode] = Users.recoveryCode.hash("r3covery") }

Content copied to clipboard

Return

The Hashed result of applying this column's Hasher to plainText.

Parameters

plainText

Value to hash

Generated by Dokka © 2026 Copyright