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

Function login

ch_10/src/routes/authentication.rs:37–63  ·  view source on GitHub ↗
(
    store: Store,
    login: Account,
)

Source from the content-addressed store, hash-verified

35}
36
37pub async fn login(
38 store: Store,
39 login: Account,
40) -> Result<impl warp::Reply, warp::Rejection> {
41 match store.get_account(login.email).await {
42 Ok(account) => match verify_password(
43 &account.password,
44 login.password.as_bytes(),
45 ) {
46 Ok(verified) => {
47 if verified {
48 Ok(warp::reply::json(&issue_token(
49 account.id.expect("id not found"),
50 )))
51 } else {
52 Err(warp::reject::custom(
53 handle_errors::Error::WrongPassword,
54 ))
55 }
56 }
57 Err(e) => Err(warp::reject::custom(
58 handle_errors::Error::ArgonLibraryError(e),
59 )),
60 },
61 Err(e) => Err(warp::reject::custom(e)),
62 }
63}
64
65fn hash_password(password: &[u8]) -> String {
66 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