liveBook · Manning

Credential

As explained in Rust Servers, Services, and Apps

User credentials are authentication information, such as a username and password, used to authenticate a user.

A credential is information used to authenticate an identity. For tutor sign-in, the credentials are a username and password entered in an HTML form. Database access has a separate set of credentials: a Postgres user and password that let the application connect to its database. section 9.1 section 4.2.2

Credentials move through the tutor application in two stages:

  • Registration collects a username and password. Browser-side checks handle required fields and field lengths; the submission handler checks whether the username already exists and whether the password matches its confirmation. section 8.2 section 8.3
  • The frontend stores the registered user in a local Postgres database. Passwords should be stored as hashes rather than clear text; the implementation uses the argon2 crate. section 8.3 section 8.2
  • At sign-in, an HTML form performs basic validation before sending a POST request. The route handler retrieves the user's credentials from the local database and verifies the submitted username and password. Failure redisplays the form with an error; success directs the user to the home page. section 9.1
#[derive(Serialize, Deserialize, Debug, sqlx::FromRow)]
pub struct User {
    pub username: String,
    pub tutor_id: i32,
    pub user_password: String,
}

The Rust User model has username, tutor_id, and user_password fields; the corresponding database table holds the registered user's record. section 8.3

Keep the two credential roles distinct when configuring the application. A Postgres user is created, granted database privileges, and tested with psql; a DATABASE_URL then supplies connection details to sqlx. Those connection credentials are not the tutor's sign-in credentials. section 4.2.2 section 9.1

In this design, the frontend owns user authentication and session management, while the backend web service handles tutor and course data. The service is intended to receive requests from the trusted frontend rather than directly from users. section 8.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Traces form submission, database storage, and sign-in verification; specifies password hashing without detailing its algorithm.
Examples
Uses a tutor registration form, a Rust User model, a Postgres user table, and a sign-in request flow.
What it assumes
Assumes familiarity with Postgres and sqlx for the tutor database, while walking through database-user setup separately.
What you can do after
Build it from scratch: collect tutor credentials, store hashed passwords locally, and check submitted credentials during sign-in.
How it connects
Connects credentials to HTML form validation, password hashing, Postgres, authentication, and frontend–backend separation.

Also explained in

Compare how 7 books explain credential →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.