1个不稳定版本
0.6.0 | 2021年7月31日 |
---|---|
0.5.0 |
|
0.4.0 |
|
0.3.0 |
|
0.1.0 |
|
#630 在 身份验证
每月 23 次下载
27KB
338 行
LrAU
LrAU是一个用于rust的身份验证和权限管理系统。它使用Argon2id对密码进行散列,以防止彩虹表和暴力破解。
示例
#[test]
fn generic() {
// Load from a toml file.
let permissions: lrau::Permissions =
toml::from_str(include_str!("./generic.toml")).unwrap();
// Create a password typical of someone who thinks their being clever.
let mut user = lrau::User::new(
String::from("john_t"),
String::from("1234"),
permissions,
);
// Valid their password
assert!(user.validate("1234"));
// Invalid their password
assert!(!user.validate("12345"));
// Permissions
// See if we have permissions to access contacts without
// mutable access.
assert!(user.get_permission(&["contacts", "name"], false));
// See if we can change users passwords with mut access.
assert!(user.get_permission(&["admin", "passwords"], true));
// Nonexisting paths inherit from paths further up the tree
assert!(user.get_permission(&["admin", "passwords", "reset"], true));
// Or are nothing if they are completely irrelevant.
assert!(!user.get_permission(&["notathing"], false));
// Checks if we have logged in (we haven't)
assert!(!user.check_login());
assert!(!user.check_valid_login());
// User Login
user.log_in("1234", std::time::Duration::from_secs(1));
// Checks for logins
assert!(user.check_login());
assert!(user.check_valid_login());
// Timeouts
std::thread::sleep(std::time::Duration::from_secs(1));
// We are still logged in...
assert!(user.check_login());
// But not validly.
assert!(!user.check_valid_login());
// And so getting vaild permissions does not work.
assert_eq!(
user.get_valid_permissions(&["admin", "passwords", "reset"], true),
Err(lrau::user::SessionExpired {}),
);
}
Serde
Serde通过serde
功能支持。如果您在toml中进行配置,可以得到类似这样的结果
[[permissions]]
path = ["contacts"]
auth = false
[[permissions]]
path = ["contacts", "name"]
auth = true
[[permissions]]
path = ["contacts", "name", "middle"]
auth = false
[[permissions]]
path = ["contacts", "name", "last"]
auth = true
[[permissions]]
path = ["admin"]
auth = false
[[permissions]]
path = ["admin", "passwords"]
auth = true
mut = true
mut
默认情况下,被假定为false
,所以您只需要在启用它时写入它。
功能
- Serde
serde
. - Diesel
diesel-support
. - Sqlx
sqlx-support
迁移者注意事项
0.6.0
修复了一个重大的安全漏洞。
0.5.0
在0.4.0版本中,所有引发恐慌的函数都已改为非恐慌。这个决定是因为一个Web服务器真的不应该崩溃。这应该主要涉及到只是在您的函数调用末尾添加?
:)
0.3.0
从版本0.3.0开始,路径现在是切片而不是字符串。这将导致与旧代码的问题,阻止其编译,并阻止读取serde信息。
依赖关系
~0.9–6.5MB
~138K SLoC