pwcheck

Crates.io Docs.rs CI RustC 1.64+

Provides a singular function to check and validate the password of a local user account on Linux, MacOS, and Windows.

Install

toml [dependencies] pwcheck = "0.1"

Usage

```rust use pwcheck::*;

fn main() { // Check if some username/password combo is valid match pwcheck("username", "password") { PwcheckResult::Ok => println!("Correct username & password!"), PwcheckResult::WrongPassword => println!("Incorrect username & password!"), PwcheckResult::Err(x) => println!("Encountered error: {x}"), } } ```

How It Works

Unix

On Unix platforms, this leverages executing su to attempt to log into the user's account and echo out a confirmation string. This requires that su be available, the underlying shell be able to receive -c to execute a command, and echo UNIQUE_CONFIRMATION be a valid command.

For most platforms, this will result in using PAM to authenticate the user by their password, which we feed in by running the su command in a tty and echoing the user's password into the tty as if it was entered manually by a keyboard.

This method acts as a convenience around the unix module's implementation, and provides a default timeout of 0.5s to wait for a success or failure before timing out.

Windows

On Windows platforms, this leverages the LogonUserW function to attempt to log a user on to the local computer.

Note that this function requires the running program to have the SeTcbPrivilege privilege set in order to log in as a user other than the user that started the program. So it's safe to use this to validate the account of the user running this program, but otherwise it needs a very high-level permission to validate the password, typically something you'd see from running the program as an administrator.

License

This project is licensed under either of

Apache License, Version 2.0, (LICENSE-APACHE or apache-license) MIT license (LICENSE-MIT or mit-license) at your option.