Bcrypt
Sign in users whose bcrypt hashes came from PHP, Rails, Django or Laravel, then move them to Quillo's Argon2.
Version 1.0.0 · 3 functions · 1 crate
Functions
What use bcrypt.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use bcrypt_verify, bcrypt_hash from bcrypt (Quillo 0.6).
bcrypt_verify(password: str, hash: str) → boolWhether password matches a bcrypt hash ($2a$, $2b$, $2y$). False for a wrong password and for anything that is not such a hash.
bcrypt_hash(password: str, cost: int) → stror an errorA bcrypt hash of password, at cost 4 to 31 (12 is usual): for systems that need bcrypt; Quillo's crypto.hash_password is better.
is_bcrypt(hash: str) → boolWhether a stored value is a bcrypt hash (and so is due for rehashing).
Get it
$ quillo install bcrypt # bcrypt.qwer into this folder$ quillo install bcrypt --example # and its example, bcrypt.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/bcrypt.qwer$ curl -O https://quillolang.org/plugins/files/bcrypt.qweThen, in your program, all of it or only what you call:
use bcrypt.qweruse bcrypt_verify, bcrypt_hash from bcrypt // Quillo 0.6: only theseIt uses this crate, which cargo fetches the first time the plugin is built:
bcrypt = "0.15"Example
// Signing in users whose passwords came from an old system, moving them to Argon2.//// quillo run bcrypt.qwe then open http://localhost:8080/loginuse "bcrypt.qwer"// A user from the old database, hashed by PHP's password_hash.let old_hash = bcrypt_hash("hunter22", 10)?fn sign_in(password: str, stored: str) { if is_bcrypt(stored) { if !bcrypt_verify(password, stored) { return { ok: false } } // Right: keep an Argon2 hash from now on. return { ok: true, rehashed: crypto.hash_password(password) } } { ok: crypto.verify_password(password, stored) }}route GET /login { let good = sign_in("hunter22", old_hash) { right: good.ok, moved_to_argon2: starts_with(good.rehashed, "$argon2id$"), wrong: sign_in("hunter2", old_hash).ok }}$ quillo run bcrypt.qwe$ curl 'localhost:8080/login'Source
//! Bcrypt hashes, to sign in users moved from PHP, Rails, Django or Laravel, then rehash them with Quillo's own Argon2.//! version: 1.0.0//!//! [dependencies]//! bcrypt = "0.15"/// Whether `password` matches a bcrypt `hash` (`$2a$`, `$2b$`, `$2y$`). False for a wrong password and for anything that is not such a hash.pub fn bcrypt_verify(password: &str, hash: &str) -> bool { bcrypt::verify(password, hash).unwrap_or(false)}/// A bcrypt hash of `password`, at `cost` 4 to 31 (12 is usual): for systems that need bcrypt; Quillo's crypto.hash_password is better.pub fn bcrypt_hash(password: &str, cost: i64) -> Result<String, String> { bcrypt::hash(password, cost.clamp(4, 31) as u32).map_err(|e| e.to_string())}/// Whether a stored value is a bcrypt hash (and so is due for rehashing).pub fn is_bcrypt(hash: &str) -> bool { hash.len() == 60 && (hash.starts_with("$2a$") || hash.starts_with("$2b$") || hash.starts_with("$2y$"))}Related
argon2.qwer · 1.0.0Argon2id password hashes with the memory and passes you choose, any Argon2 hash verified, its parameters read, old ones marked for a rehash, and the cost timed on this server.7 views · 6 downloadsLegacy passwords legacy_passwords.qwer · 1.0.0Check passwords against Django, Flask/Werkzeug and WordPress hashes, to sign in users moved from those apps and rehash them with Argon2.7 views · 7 downloadsScrypt passwords scrypt.qwer · 1.0.0Scrypt password hashes made, checked and marked for a rehash, the raw key Node's crypto.scrypt makes, and Firebase Authentication's modified scrypt, to sign in users exported from Firebase.6 views · 7 downloadsPassword strength password_strength.qwer · 1.0.0How guessable a password is (zxcvbn): a score from 0 to 4, a warning and suggestions, and how long it would take to crack.6 views · 8 downloadsPwned passwords pwned.qwer · 1.0.0Have I Been Pwned's Pwned Passwords by k-anonymity: only 5 characters of the SHA-1 leave the server, the answer is checked here.8 views · 9 downloadsRecovery codes mfa_codes.qwer · 1.0.0Two-factor recovery codes: a set made and shown once, stored only as hashes, each one usable a single time.7 views · 6 downloadsThread 0 posts
On Bcrypt: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.