eltNEG/passprompt
A simple Zig library for secure password input from the terminal with customizable display options
A simple Zig library for secure password input from the terminal with customizable display options.
Fetch this dependency by running the following command in your project:
zig fetch --save git+https://github.com/eltNEG/passprompt#master
Then in your build.zig:
const passprompt_dep = b.dependency("passprompt", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("passprompt", passprompt_dep.module("passprompt"));
pub fn main() !void {
var buffer: [256]u8 = undefined;
// Get password with asterisk masking
const size = try passprompt.get(&buffer, "Enter password: ", '*');
const password = buffer[0..size];
// Get password with no display (completely hidden)
var buffer2: [256]u8 = undefined;
const size2 = try passprompt.get(&buffer2, "Enter secret: ", null);
const secret = buffer2[0..size2];
// Check if passwords match
const match = std.mem.eql(u8, password, secret);
std.debug.print("Passwords match: {}\n", .{match});
}
get(buffer: []u8, msg: []const u8, display: ?u8) !usizePrompts the user for password input.
Parameters:
buffer: Byte slice to store the input passwordmsg: Prompt message to display to the userdisplay: Optional character to display instead of the actual input'*' - Show asterisks for each character'#' - Show hash symbols for each characternull - Completely hide input (no visual feedback)Returns:
usize: Number of characters entered (excluding newline)Errors: