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§
- User
Token - Holds user token.
Constants§
- DAYS_
VALID - Limit of token validation time (each token lives 28 days).
- MAX_
TOKENS_ PER_ USER - Limit of tokens for one user (3 tokens). If the token limit is exceeded, old tokens will be overwritten.
Functions§
- check_
and_ remove_ token - Removes the valid token from Redis-like DB.
- check_
token - Validates the user by token via Redis-like DB.
- generate_
salt - Generates salt for new user.
- generate_
token - Generates new token for user.
- get_
user_ tokens_ list_ name - Returns the name of the list in Redis-like DB that stores the users’ tokens.
- hash_
password - Gets the salted password’s SHA3-256 hash.
- hashes_
eq - Checks the password is correct.
- log_in
- Authorizes the user by creating a new token for him if the data is correct.