MCPcopy Index your code
hub / github.com/Rust-Web-Development/code / login

Function login

ch_09/src/routes/authentication.rs:39–65  ·  view source on GitHub ↗
(
    store: Store,
    login: Account,
)

Source from the content-addressed store, hash-verified

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