user_trait

Crates.iouser_trait
lib.rsuser_trait
version0.1.1
created_at2025-01-14 17:57:35.190156+00
updated_at2025-01-14 18:12:33.209221+00
descriptionA library for user authentication abstraction in Rust.
homepagehttps://github.com/e1732a364fed/user_trait
repositoryhttps://github.com/e1732a364fed/user_trait
max_upload_size
id1516413
size13,051
e1732a364fed (e1732a364fed)

documentation

README

User-Trait

This library provides basic traits and helper structures for user authentication in Rust. It includes functionality for user identification, authentication, and storage, aiming to provide a simple enough interface for user authentication.

Features

  • UserTrait: A trait defining methods for user identification and authentication.
  • UserBox: A wrapper for a boxed user implementing the User trait, with support for hashing and ordering.
  • UserVec: A vector of UserBox with additional functionality for sorting and hashing.
  • UserAuthenticator: A trait for user authentication.
  • PlainText: A simple implementation of a user with plaintext username and password.
  • UsersMap: A map for storing users, implementing UserAuthenticator.

Usage

To use this library, add it as a dependency in your Cargo.toml:

[dependencies]
user_trait = "0.1.0"
use user_trait::{PlainText, UsersMap, UserAuthenticator};

fn main() {
    let user1 = PlainText::new("user1".to_string(), "password1".to_string());
    let user2 = PlainText::new("user2".to_string(), "password2".to_string());
    let mut users_map = UsersMap::new();
    users_map.add_user(user1);
    users_map.add_user(user2);

    if let Some(authenticated_user) = users_map.auth_user_by_authstr("plaintext:user2\npassword2") {

        println!("User authenticated: {}", authenticated_user.identity_str());
    } else {
        println!("Authentication failed.");
    }
}

Similar Projects

password-hash

License

This project is licensed under the MIT OR Apache-2.0 License.

Commit count: 8

cargo fmt