std/bcrypt
On this page
Index
- const
MIN_COST - const
MAX_COST - const
DEFAULT_COST - type
BcryptErr- method
BcryptErr.display
- method
- fn
hash - fn
compare - fn
cost
Constants
MIN_COST
const MIN_COST: Int = 4The lowest cost hash accepts; a lower one is replaced by DEFAULT_COST
(Go’s MinCost).
MAX_COST
const MAX_COST: Int = 31The highest cost (Go’s MaxCost).
DEFAULT_COST
const DEFAULT_COST: Int = 10The cost hash uses by default and for a cost below MIN_COST (Go’s
DefaultCost).
Types
BcryptErr
enum BcryptErr {
Mismatch
HashTooShort
VersionTooNew(version: Int)
InvalidPrefix(byte: Int)
InvalidCost(cost: Int)
PasswordTooLong
Corrupt(msg: Str)
}Go’s errors, with Go’s texts as display(): crypto/bcrypt: hashedPassword is not the hash of the given password, crypto/bcrypt: hashedSecret too short to be a bcrypted password, crypto/bcrypt: bcrypt algorithm version '3' requested is newer than current version '2',
crypto/bcrypt: bcrypt hashes must start with '$', but hashedSecret started with 'x', crypto/bcrypt: cost 3 is outside allowed inclusive range 4..31, bcrypt: password length exceeds 72 bytes; Corrupt is a
cost or salt that is not valid text (Go’s strconv and base64 errors).
BcryptErr.display
fn (e: BcryptErr) display() -> StrFunctions
hash
fn hash(password: Bytes, rand: Rand, cost: Int = 10) -> Str ! BcryptErr uses randA new hash of password (Go’s GenerateFromPassword): 60 characters,
with a random salt drawn from rand. A cost below MIN_COST is
DEFAULT_COST; above MAX_COST is InvalidCost; a password over 72 bytes
is PasswordTooLong.
compare
fn compare(hashed: Str, password: Bytes) -> () ! BcryptErrOk when hashed is the bcrypt hash of password (Go’s
CompareHashAndPassword), Mismatch when it is not, and the other
errors when hashed is not a bcrypt hash. The comparison of the hashes
takes the same time wherever they differ.
cost
fn cost(hashed: Str) -> Int ! BcryptErrThe cost hashed was made with (Go’s Cost).
↑ index