Skip to content

CLI password generator using C and /dev/urandom

License

Notifications You must be signed in to change notification settings

nico-castell/genpass2

Repository files navigation

CLI Password Generator 2

Commits since last release Release License Lines of code CodeQL

This is a replacement program for the Golang based genpass proyect. By using C and reading the file /dev/urandom directly, this program can achieve absurdly superior speeds when generating very large ammounts of random data.

Note that, unlike genpass, this program does not run on Windows.

Usage

  • Standalone: You can run it without arguments, and it will default to an 8 character password, or you can specify the length as follows:
     genpass2 16
    If you input a negative number (such as -128), the program will error and tell you that it's not a valid number. Any arguments after the first will be ignored. The maximum number of characters the password can have is 4,294,967,296. Why? Because for every character in the password, we need a byte in memory.
  • Variable: This is the recommended way. You store the output in a variable, so the password never appears on screen.
     MY_PASS=$(genpass2 16)
  • Clipboard: You can also put the password in your clipboard using the xclip command.
     genpass2 16 | xclip -selection clipboard -i
  • Manpage: You can view the manpage if you need to see this information in the command line.
     man genpass2

Build instructions and installation

To build this project you will need two things, Meson and a C compiler.

  1. First, clone this repository and change directory into it:
    git clone https://github.com/nico-castell/genpass2.git
    cd genpass2
  2. Second, prepare the build folder using meson:
    meson --buildtype=release build
    You can also use the following flag:
    --prefix=~/.local  # To install this program for the current user
  3. Use meson to build and install the project:
    meson install -C build

Packaging the project and installing it

Thanks to the use of Makefiles, packaging the project as a .rpm or .deb is very easy. Just follow these steps:

  • If you're on Fedora or another RHEL based OS:

     cd rpmbuild
     make

    If you then want to install the package:

     sudo dnf install ./RPMS/$(uname -m)/genpass2-1.0.2-1.*.rpm

    If you want to remove the package:

     sudo dnf remove genpass2

    You will need to have rpmdevtools installed to build the package.

  • If you're on Debian or another Debian based OS:

     cd debian
     make

    If you then want to install the package:

     sudo apt install ./DEBS/genpass2_1.0.2-1*.deb

    If you want to remove the package:

     sudo apt remove genpass2

    You will need to have dpkg-dev and debhelper installed to build the package.

  • You can also use the tarpkg directory to build a tar archive you can deploy in /usr/local in case your system doesn't use either dnf (rpm) or apt (dpkg).

     cd tarpkg
     make

About

This program and this repository are availabe under an MIT License.