1个不稳定版本

0.2.3 2023年10月14日

#699 in 认证

Download history 6/week @ 2024-03-12 1/week @ 2024-03-26 7/week @ 2024-04-02 1/week @ 2024-04-30 1/week @ 2024-05-14 4/week @ 2024-05-28 42/week @ 2024-06-04 8/week @ 2024-06-11 1/week @ 2024-06-18 5/week @ 2024-06-25

60 每月下载量

AGPL-3.0-or-later

265KB
357

Argon2-Creds

Argon2-Creds - 对凭证管理的便捷抽象

status-badge dependency status

功能

  • PRECIS框架 UsernameCaseMapped
  • 使用rust-argon2进行密码哈希和验证
  • 对可能引起歧义的单词进行过滤。见黑名单
  • 粗俗语过滤器
  • 电子邮件验证(正则表达式验证而非验证)

用法

将此添加到您的Cargo.toml

argon2-creds = "0.2"

示例

  1. 使用此crate的最简单方法是使用默认配置。请参阅默认配置的Default实现。
use argon2_creds::Config;

fn main() {
   let config = Config::default();

   let password = "ironmansucks";

   // email validation
   config.email(Some("[email protected]")).unwrap();

   // process username
   let username = config.username("Realaravinth").unwrap(); // process username

   // generate hash
   let hash = config.password(password).unwrap();

   assert_eq!(username, "realaravinth");
   assert!(Config::verify(&hash, password).unwrap(), "verify hashing");
}
  1. 要获得对凭证管理的细粒度控制,请考虑使用[ConfigBuilder]
use argon2_creds::{Config, ConfigBuilder, PasswordPolicyBuilder};

fn main() {
    let config = ConfigBuilder::default()
        .username_case_mapped(false)
        .profanity(true)
        .blacklist(false)
        .password_policy(
            PasswordPolicyBuilder::default()
                .min(12)
                .max(80)
                .build()
                .unwrap(),
        )
        .build()
        .unwrap();

    let password = "ironmansucks";
    let hash = config.password(password).unwrap();

    // email validation
    config.email(Some("[email protected]")).unwrap();

    // process username
    let username = config.username("Realaravinth").unwrap(); // process username

    // generate hash
    let hash = config.password(password).unwrap();

    assert_eq!(username, "realaravinth");
    assert!(Config::verify(&hash, password).unwrap(), "verify hashing");
}

依赖关系

~8–16MB
~224K SLoC