Expand description
Crate that implementing simple authorization system.
CC Auth uses passwords’ hashing with salts, SHA3-256 hash function and Redis-like tokens’ storage.
Usage:
use bb8_redis::{RedisConnectionManager, bb8::Pool};
use cc_auth::{ApiToken, check_token};
use cc_utils::prelude::MResult;
pub async fn authorized_action(
cacher: &Pool<RedisConnectionManager>,
token: ApiToken,
) -> MResult<()> {
let user_id = check_token(&token, cacher).await?;
Ok(())
}Structs§
- Holds user token.
Constants§
- Limit of token validation time (each token lives 28 days).
- Limit of tokens for one user (3 tokens). If the token limit is exceeded, old tokens will be overwritten.
Functions§
- Removes the valid token from Redis-like DB.
- Validates the user by token via Redis-like DB.
- Generates salt for new user.
- Generates new token for user.
- Returns the name of the list in Redis-like DB that stores the users’ tokens.
- Gets the salted password’s SHA3-256 hash.
- Checks the password is correct.
- Authorizes the user by creating a new token for him if the data is correct.
Type Aliases§
- Token as string (e.g. one that got from
Authorizationheader). - User identifier type.