bcrypt

Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
3 months ago
Downloads
21

#hackwaly/bcrypt

Pure MoonBit bcrypt core implementation.

///|
test "bcrypt example" {
let salt = Bytes::from_array([
(0x71).to_byte(),
(0xd7).to_byte(),
(0x9f).to_byte(),
(0x82).to_byte(),
(0x18).to_byte(),
(0xa3).to_byte(),
(0x92).to_byte(),
(0x59).to_byte(),
(0xa7).to_byte(),
(0xa2).to_byte(),
(0x9a).to_byte(),
(0xab).to_byte(),
(0xb2).to_byte(),
(0xdb).to_byte(),
(0xaf).to_byte(),
(0xc3).to_byte(),
])
let hash = @bcrypt.hash_password(b"password", salt, 4).unwrap()
assert_eq(@bcrypt.verify(b"password", hash), Ok(true))
assert_eq(@bcrypt.verify(b"wrong", hash), Ok(false))
}

BcryptError

pub suberror BcryptError {
InvalidCost(Int)
InvalidSaltLength(Int)
InvalidHashFormat
UnsupportedVersion(String)
InvalidBase64
} derive(Eq,
Debug
)

impl Show for BcryptError

cost

fn cost(hash : String) -> Result[Int, BcryptError]

hash_length

let hash_length : Int

hash_password

fn hash_password(password : Bytes, salt : Bytes, cost : Int) -> Result[String, BcryptError]

max_cost

let max_cost : Int

min_cost

let min_cost : Int

salt_length

let salt_length : Int

verify

fn verify(password : Bytes, hash : String) -> Result[Bool, BcryptError]

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io