Expand description

Readable password generator

Generate a readable password from an ordered list of words extracted from text. For improved security, numbers and special characters are inserted at random places.

The point is to replace the standard password generation that is very tedious to input manually, with a still very secure but much easier to write password. For the rare occasion where you have to input it manually, like on a smartphone you’re not syncing them to. It also makes for some interesting passwords, depending on what you choose to use as source.

Written based on a Computerphile video: How to Choose a Password.


use genrepass::*;
use std::error::Error;
use std::process::exit;

fn main() {
    // Take care of errors.
    if let Err(e) = run() {
        eprintln!("Error: {}.", e);

// Create a function for easier error management.
fn run() -> Result<(), Box<dyn Error>> {
    // Create a configuration with default values.
    let mut config = PassConfig::new();

    // Load in and parse the text to use for the password generation.

    // Can be done multiple times to add different directories or files.

    // Can also just load it from a String.
    config.get_words_from_str("A string I got from somewhere");

    // Change the configuration by changing the fields.
    config.pass_amount = 5;
    config.capitalise = true;
    config.length = "30-50".to_string();

    // Check that the configuration is valid.
    let validated = config.validate()?;

    // Generate the password/s based on the validated configuration.
    let passwords = validated.generate();

    // Use the vector however you need.
    // In this case we put each password on a separate line and print them.
    println!("{}", passwords.join("\n"));



Used for configuring the password generator.
Holds the message for the type of error that occurred while parsing a range.
Immutable configuration given after validation.


The possible errors when checking the configuration.