Compare commits

..
Author SHA1 Message Date
phoenix 14259c6c38 Update soaricarus dependencies (#13)
Release Tagging / release (push) Successful in 26s
soaricarus_auth Build / Check (push) Successful in 32s
soaricarus_auth Build / Rustfmt (push) Successful in 32s
soaricarus_auth Build / Clippy (push) Successful in 33s
soaricarus_auth Build / Test Suite (push) Successful in 37s
soaricarus_auth Build / build (push) Successful in 2m15s
soaricarus_auth Build / Clippy (pull_request) Failing after 37s
soaricarus_auth Build / Rustfmt (pull_request) Failing after 40s
soaricarus_auth Build / Test Suite (pull_request) Successful in 1m53s
soaricarus_auth Build / Check (pull_request) Successful in 4m3s
soaricarus_auth Build / build (pull_request) Successful in 4m41s
Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_auth/pulls/13
2026-11-05 16:20:59 -05:00
phoenix 778be1f4a2 Bump argon2 (#12)
Release Tagging / release (push) Successful in 25s
soaricarus_auth Build / Check (push) Successful in 28s
soaricarus_auth Build / Rustfmt (push) Successful in 21s
soaricarus_auth Build / Test Suite (push) Successful in 43s
soaricarus_auth Build / Clippy (push) Successful in 48s
soaricarus_auth Build / build (push) Successful in 2m6s
soaricarus_auth Build / Rustfmt (pull_request) Successful in 21s
soaricarus_auth Build / Clippy (pull_request) Successful in 28s
soaricarus_auth Build / build (pull_request) Successful in 47s
soaricarus_auth Build / Check (pull_request) Successful in 2m22s
soaricarus_auth Build / Test Suite (pull_request) Successful in 2m42s
Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_auth/pulls/12
2026-11-01 19:18:31 -05:00
phoenix de4c698836 bump: uuid (#11)
soaricarus_auth Build / Check (push) Successful in 20s
Release Tagging / release (push) Successful in 26s
soaricarus_auth Build / Test Suite (push) Successful in 37s
soaricarus_auth Build / Rustfmt (push) Successful in 18s
soaricarus_auth Build / Clippy (push) Successful in 1m40s
soaricarus_auth Build / build (push) Successful in 1m53s
Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_auth/pulls/11
2026-11-01 10:52:10 -05:00
5 changed files with 125 additions and 110 deletions

No files matched your search

Generated
+60 -73
View File
@@ -31,13 +31,13 @@ checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]] [[package]]
name = "argon2" name = "argon2"
version = "0.5.3" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072" checksum = "134c52ddac6d63c576bef8168db10c83c49c26444ecbc68060fef078925a901c"
dependencies = [ dependencies = [
"base64ct", "base64ct",
"blake2", "blake2",
"cpufeatures 0.2.17", "cpufeatures 0.3.1",
"password-hash", "password-hash",
] ]
@@ -143,11 +143,11 @@ dependencies = [
[[package]] [[package]]
name = "blake2" name = "blake2"
version = "0.10.6" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" checksum = "5b5d4d889834ee8ecfc0f8426ad30faf7cdcb10f741a8e6d7224d95325479f6f"
dependencies = [ dependencies = [
"digest 0.10.7", "digest 0.11.3",
] ]
[[package]] [[package]]
@@ -188,9 +188,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.10.0" version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86e055fa6e3e40ad6187ba25b6855eeb635d5271f8e0f0e1e9a5826b8d75bea0" checksum = "375989decec1a0fa424442bed520fa12ede43a48475ce8c7417d2c69b32b5f6b"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"shlex", "shlex",
@@ -216,7 +216,7 @@ checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cpufeatures 0.3.1", "cpufeatures 0.3.1",
"rand_core 0.10.1", "rand_core",
] ]
[[package]] [[package]]
@@ -297,9 +297,9 @@ checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853"
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.5.3" version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ba106e844045ddc02c20768ac4b0b7cb45f2cc2ecbd833ac9f5dacb183c2055" checksum = "5f97d3416d5337d15c4b0d78c8c91df922ca143f57ec20e2d1c188333047ef04"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
@@ -321,9 +321,9 @@ checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.7" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"typenum", "typenum",
@@ -340,9 +340,9 @@ dependencies = [
[[package]] [[package]]
name = "ctutils" name = "ctutils"
version = "0.4.7" version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2376ffd6f96d8a9db59875b4b6b0237d6900b5baf64279714e05493ce64828a" checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f"
dependencies = [ dependencies = [
"cmov", "cmov",
] ]
@@ -363,8 +363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [ dependencies = [
"block-buffer 0.10.4", "block-buffer 0.10.4",
"crypto-common 0.1.7", "crypto-common 0.1.6",
"subtle",
] ]
[[package]] [[package]]
@@ -577,25 +576,14 @@ dependencies = [
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2"
dependencies = [ dependencies = [
"typenum", "typenum",
"version_check", "version_check",
] ]
[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.4.3" version = "0.4.3"
@@ -606,7 +594,7 @@ dependencies = [
"js-sys", "js-sys",
"libc", "libc",
"r-efi", "r-efi",
"rand_core 0.10.1", "rand_core",
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -974,9 +962,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.34" version = "0.4.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
[[package]] [[package]]
name = "matchit" name = "matchit"
@@ -1002,9 +990,9 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.17" version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "d5848f5a9e8117cf94f2f90faac24a87ff81600ff8628c1e3deaab572e76bfa1"
[[package]] [[package]]
name = "mime_guess" name = "mime_guess"
@@ -1098,9 +1086,9 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.81" version = "0.10.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45" checksum = "4de8111e94a56adca7ebfe6c365b6d42f99deb69b74b6becacd4204e2f193aa2"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if",
@@ -1138,9 +1126,9 @@ dependencies = [
[[package]] [[package]]
name = "openssl-sys" name = "openssl-sys"
version = "0.9.117" version = "0.9.118"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695" checksum = "19c413d6ec9ebaf5e1c829d355cb3e9f783778d700f135be0921d52fce3c60ae"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@@ -1180,13 +1168,13 @@ dependencies = [
[[package]] [[package]]
name = "password-hash" name = "password-hash"
version = "0.5.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" checksum = "aab41826031698d6ffcd9cff78ef56ef998e39dc7e5067cdfebe373842d4723b"
dependencies = [ dependencies = [
"base64ct", "getrandom",
"rand_core 0.6.4", "phc",
"subtle", "rand_core",
] ]
[[package]] [[package]]
@@ -1195,6 +1183,18 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "phc"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44dc769b75f93afdddd8c7fa12d685292ddeff1e66f7f0f3a234cf1818afe892"
dependencies = [
"base64ct",
"ctutils",
"getrandom",
"rand_core",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.17" version = "0.2.17"
@@ -1253,17 +1253,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
dependencies = [ dependencies = [
"chacha20", "chacha20",
"getrandom 0.4.3", "getrandom",
"rand_core 0.10.1", "rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom 0.2.17",
] ]
[[package]] [[package]]
@@ -1491,8 +1482,8 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]] [[package]]
name = "sienvy" name = "sienvy"
version = "0.8.2" version = "0.8.3"
source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.2#492c3e04d1b3f49fcdfe4af71ce0686fa4649526" source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.3#71544fd2e8d217eac5fc51b14bb062c302465718"
dependencies = [ dependencies = [
"const_format", "const_format",
"dotenvy", "dotenvy",
@@ -1506,8 +1497,8 @@ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
[[package]] [[package]]
name = "simodels" name = "simodels"
version = "0.11.7" version = "0.11.9"
source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.7#6022347cb762b413bb59b975619577a45d26383f" source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.9#8e91af657e2e1f124bbba9547ee7e6936f6bb249"
dependencies = [ dependencies = [
"josekit", "josekit",
"rand", "rand",
@@ -1535,13 +1526,14 @@ dependencies = [
[[package]] [[package]]
name = "soaricarus_auth" name = "soaricarus_auth"
version = "0.8.5" version = "0.8.8"
dependencies = [ dependencies = [
"argon2", "argon2",
"axum", "axum",
"http-body-util", "http-body-util",
"josekit", "josekit",
"openssl", "openssl",
"rand",
"serde", "serde",
"serde_json", "serde_json",
"sienvy", "sienvy",
@@ -1774,12 +1766,6 @@ dependencies = [
"unicode-properties", "unicode-properties",
] ]
[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.119" version = "2.0.119"
@@ -1826,7 +1812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [ dependencies = [
"fastrand", "fastrand",
"getrandom 0.4.3", "getrandom",
"once_cell", "once_cell",
"rustix", "rustix",
"windows-sys", "windows-sys",
@@ -2103,9 +2089,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-properties" name = "unicode-properties"
version = "0.1.4" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" checksum = "993ad287eb20e8ba755312801cfe1413e0f25d604075863acaddca10b04c1833"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
@@ -2188,7 +2174,7 @@ version = "1.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514" checksum = "4a0e2d11620c50695fe12bbbfde96b3477fe606e7284c22d505c12ce51214514"
dependencies = [ dependencies = [
"getrandom 0.4.3", "getrandom",
"js-sys", "js-sys",
"serde_core", "serde_core",
"wasm-bindgen", "wasm-bindgen",
@@ -2368,14 +2354,15 @@ dependencies = [
[[package]] [[package]]
name = "zip" name = "zip"
version = "9.1.3" version = "9.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1156b39d142a34b999c2310a50455e0cb3760bf7efad0122f796d813bee26ccb" checksum = "3cec733c9820347a592f6375c3c0089b479ba0a0b1cbf3dd1958b02959b7c033"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"flate2", "flate2",
"getrandom 0.4.3", "getrandom",
"indexmap", "indexmap",
"libc",
"memchr", "memchr",
"nix", "nix",
"typed-path", "typed-path",
+7 -6
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "soaricarus_auth" name = "soaricarus_auth"
version = "0.8.5" version = "0.8.8"
edition = "2024" edition = "2024"
rust-version = "1.95" rust-version = "1.95"
license = "MIT" license = "MIT"
@@ -8,7 +8,7 @@ description = "Auth API for soaricarus"
[dependencies] [dependencies]
axum = { version = "0.8.9" } axum = { version = "0.8.9" }
openssl = { version = "0.10.81", features = ["vendored"] } openssl = { version = "0.10.82", features = ["vendored"] }
serde = { version = "1.0.229", features = ["derive"] } serde = { version = "1.0.229", features = ["derive"] }
serde_json = { version = "1.0.154" } serde_json = { version = "1.0.154" }
tokio = { version = "1.54.1", features = ["rt-multi-thread"] } tokio = { version = "1.54.1", features = ["rt-multi-thread"] }
@@ -16,14 +16,15 @@ tracing-subscriber = { version = "0.3.23" }
tower = { version = "0.5.3", features = ["full"] } tower = { version = "0.5.3", features = ["full"] }
tower-http = { version = "0.7.1", features = ["cors"] } tower-http = { version = "0.7.1", features = ["cors"] }
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
uuid = { version = "1.27.0", features = ["v4", "serde"] } uuid = { version = "1.29.0", features = ["v4", "serde"] }
argon2 = { version = "0.5.3", features = ["std"] } argon2 = { version = "0.6.0", features = ["alloc", "getrandom", "rand_core"] }
time = { version = "0.3.55", features = ["macros", "serde"] } time = { version = "0.3.55", features = ["macros", "serde"] }
josekit = { version = "0.10.3" } josekit = { version = "0.10.3" }
utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] } utoipa = { version = "6.0.0", features = ["axum_extras", "uuid", "time"] }
utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] } utoipa-swagger-ui = { version = "10.0.2", features = ["axum"] }
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.7" } rand = { version = "0.10.3" }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.2" } simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.9", features = ["auth"] }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.3" }
[dev-dependencies] [dev-dependencies]
http-body-util = { version = "0.1.5" } http-body-util = { version = "0.1.5" }
+5 -4
View File
@@ -151,7 +151,7 @@ pub mod endpoint {
id: user.id, id: user.id,
username: user.username.clone(), username: user.username.clone(),
token: token_literal, token: token_literal,
token_type: String::from(simodels::token::TOKEN_TYPE), token_type: simodels::constants::token::TOKEN_TYPE.to_string(),
expiration: duration, expiration: duration,
}], }],
}), }),
@@ -203,7 +203,7 @@ pub mod endpoint {
id, id,
username, username,
token: token_literal, token: token_literal,
token_type: String::from(simodels::token::TOKEN_TYPE), token_type: simodels::constants::token::TOKEN_TYPE.to_string(),
expiration: duration, expiration: duration,
}; };
@@ -262,7 +262,8 @@ pub mod endpoint {
id, id,
token: access_token, token: access_token,
expiration: exp_dur, expiration: exp_dur,
token_type: String::from(simodels::token::TOKEN_TYPE), token_type: simodels::constants::token::TOKEN_TYPE
.to_string(),
username, username,
}; };
response.message = String::from("Successful"); response.message = String::from("Successful");
@@ -344,7 +345,7 @@ pub mod endpoint {
Ok(salt) => { Ok(salt) => {
let updated_salt_string = hashing::generate_salt().unwrap(); let updated_salt_string = hashing::generate_salt().unwrap();
let updated_salt = simodels::user::salt::Salt { let updated_salt = simodels::user::salt::Salt {
salt: updated_salt_string.to_string(), salt: updated_salt_string.to_string().clone(),
id: salt.id, id: salt.id,
}; };
let updated_hashed_password = hashing::hash_password( let updated_hashed_password = hashing::hash_password(
+1 -1
View File
@@ -93,7 +93,7 @@ pub async fn register_user(
let salt_string = hashing::generate_salt().unwrap(); let salt_string = hashing::generate_salt().unwrap();
let mut salt = simodels::user::salt::Salt::default(); let mut salt = simodels::user::salt::Salt::default();
let generated_salt = salt_string; let generated_salt = salt_string;
salt.salt = generated_salt.to_string(); salt.salt = generated_salt.to_string().clone();
salt.id = repo::salt::insert(&pool, &salt).await.unwrap(); salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
user.salt_id = salt.id; user.salt_id = salt.id;
let hashed_password = let hashed_password =
+52 -26
View File
@@ -1,17 +1,39 @@
use argon2::{ use argon2::{Argon2, PasswordVerifier, password_hash::PasswordHasher};
Argon2, // The Argon2 algorithm struct use rand::distr::SampleString;
PasswordVerifier,
password_hash::{ pub struct SaltString {
PasswordHasher, pub raw: String,
SaltString, pub in_bytes: Vec<u8>,
rand_core::OsRng, // Secure random number generator }
},
}; impl SaltString {
pub fn generate() -> Result<SaltString, argon2::Error> {
let mut rng = rand::rng();
let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20);
let salt_string = SaltString {
raw: s.to_string(),
in_bytes: s.into_bytes(),
};
Ok(salt_string)
}
pub fn from_b64(s: &str) -> Result<SaltString, argon2::password_hash::Error> {
let salt_string = SaltString {
raw: (&s).to_string(),
in_bytes: s.to_string().into_bytes(),
};
Ok(salt_string)
}
pub fn to_string(&self) -> &String {
&self.raw
}
}
pub fn generate_salt() -> Result<SaltString, argon2::Error> { pub fn generate_salt() -> Result<SaltString, argon2::Error> {
// Generate a random salt SaltString::generate()
// SaltString::generate uses OsRng internally for cryptographic security
Ok(SaltString::generate(&mut OsRng))
} }
pub fn get_salt(s: &str) -> Result<SaltString, argon2::password_hash::Error> { pub fn get_salt(s: &str) -> Result<SaltString, argon2::password_hash::Error> {
@@ -24,14 +46,11 @@ pub fn hash_password(
) -> Result<String, argon2::password_hash::Error> { ) -> Result<String, argon2::password_hash::Error> {
let password_bytes = password.as_bytes(); let password_bytes = password.as_bytes();
// Create an Argon2 instance with default parameters (recommended)
// You could customize parameters here if needed, but defaults are strong
let argon2 = Argon2::default(); let argon2 = Argon2::default();
// Hash the password with the salt Ok(argon2
// The output is a PasswordHash string format that includes algorithm, version, .hash_password_with_salt(password_bytes, &salt.in_bytes)?
// parameters, salt, and the hash itself. .to_string())
Ok(argon2.hash_password(password_bytes, salt)?.to_string())
} }
pub fn verify_password( pub fn verify_password(
@@ -48,9 +67,9 @@ pub fn verify_password(
// Verify the password against the parsed hash // Verify the password against the parsed hash
// This automatically uses the correct salt and parameters embedded in `parsed_hash` // This automatically uses the correct salt and parameters embedded in `parsed_hash`
match Argon2::default().verify_password(password_bytes, &parsed_hash) { match Argon2::default().verify_password(password_bytes, &parsed_hash) {
Ok(()) => Ok(true), // Passwords match Ok(()) => Ok(true), // Passwords match
Err(argon2::password_hash::Error::Password) => Ok(false), // Passwords don't match Err(argon2::password_hash::Error::PasswordInvalid) => Ok(false), // Passwords don't match
Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format) Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format)
} }
} }
@@ -58,10 +77,15 @@ pub fn verify_password(
mod tests { mod tests {
use super::*; use super::*;
pub const TEST_PASSWORD: &str = "somethingrandom";
pub const TEST_WRONG_PASSWORD: &str = "Differentanotherlevel";
#[test] #[test]
fn test_hash_password() { fn test_hash_password() {
let some_password = String::from("somethingrandom"); let some_password = String::from(TEST_PASSWORD);
match hash_password(&some_password, &generate_salt().unwrap()) { let salt = generate_salt().unwrap();
match hash_password(&some_password, &salt) {
Ok(p) => match verify_password(&some_password, p.clone()) { Ok(p) => match verify_password(&some_password, p.clone()) {
Ok(res) => { Ok(res) => {
assert_eq!(res, true); assert_eq!(res, true);
@@ -78,8 +102,10 @@ mod tests {
#[test] #[test]
fn test_wrong_password() { fn test_wrong_password() {
let some_password = String::from("somethingrandom"); let some_password = String::from(TEST_PASSWORD);
match hash_password(&some_password, &generate_salt().unwrap()) { let salt = generate_salt().unwrap();
match hash_password(&some_password, &salt) {
Ok(p) => { Ok(p) => {
match verify_password(&some_password, p.clone()) { match verify_password(&some_password, p.clone()) {
Ok(res) => { Ok(res) => {
@@ -89,7 +115,7 @@ mod tests {
assert!(false, "Error: {:?}", err.to_string()); assert!(false, "Error: {:?}", err.to_string());
} }
} }
let wrong_password = String::from("Differentanotherlevel"); let wrong_password = String::from(TEST_WRONG_PASSWORD);
let result = verify_password(&wrong_password, p.clone()).unwrap(); let result = verify_password(&wrong_password, p.clone()).unwrap();
assert_eq!(false, result, "Passwords should not match"); assert_eq!(false, result, "Passwords should not match");
} }