Zig
Zig
Generating Random Password
See more PRNG Examples
Demonstrates how to generate random passwords.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
success = false;
const fortuna = try chilkat.Prng.init();
defer fortuna.deinit();
// Set this equal to true if the generated password must include at least one digit (0-9)
const b_digit = true;
// Set this equal to true if the generated password must include both uppercase and lowercase chars.
const b_upper_and_lower = true;
// The generated password must contain one of the following non-alphanumeric chars.
const other_chars = "@#$%*";
// Exclude chars that appear similar to others:
const exclude_chars = "iIlLoO0";
// Generate 8-character passwords:
var i: i32 = 0;
i = 1;
while (i <= 10) : (i += 1) {
std.debug.print("{s}\n", .{try fortuna.randomPassword(alloc, 8, b_digit, b_upper_and_lower, other_chars, exclude_chars)});
}
}