MCPcopy Create free account
hub / github.com/Rust-Web-Development/code / login

Function login

ch_11/src/routes/authentication.rs:31–49  ·  view source on GitHub ↗
(store: Store, login: Account)

Source from the content-addressed store, hash-verified

29}
30
31pub async fn login(store: Store, login: Account) -> Result<impl warp::Reply, warp::Rejection> {
32 match store.get_account(login.email).await {
33 Ok(account) => match verify_password(&account.password, login.password.as_bytes()) {
34 Ok(verified) => {
35 if verified {
36 Ok(warp::reply::json(&issue_token(
37 account.id.expect("id not found"),
38 )))
39 } else {
40 Err(warp::reject::custom(handle_errors::Error::WrongPassword))
41 }
42 }
43 Err(e) => Err(warp::reject::custom(
44 handle_errors::Error::ArgonLibraryError(e),
45 )),
46 },
47 Err(_) => Err(warp::reject::custom(handle_errors::Error::WrongPassword)),
48 }
49}
50
51fn hash_password(password: &[u8]) -> String {
52 let salt = SaltString::generate(&mut OsRng);

Callers

nothing calls this directly

Calls 3

verify_passwordFunction · 0.70
issue_tokenFunction · 0.70
get_accountMethod · 0.45

Tested by

no test coverage detected