Something went wrong. Try again.
passlib's password hash schemes, ported to Zig 0.16
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! The Roundup issue tracker's password formats: passlib's//! `passlib.handlers.roundup`.//!//! Roundup stored passwords as `{SCHEME}` strings the way LDAP does, but with//! the digests in hex rather than base64: `{MD5}` and `{SHA}` followed by a//! hex digest, and `{plaintext}` followed by the password itself. They are//! unsalted, and `{plaintext}` is not a hash at all. They are here to read//! what Roundup stored.
const std = @import("std");const testing = std.testing;
const handler = @import("../handler.zig");const Context = handler.Context;const digests = @import("digests.zig");const misc = @import("misc.zig");
pub const ldap_hex_md5 = handler.PrefixWrapper("ldap_hex_md5", digests.hex_md5, "{MD5}", "");pub const ldap_hex_sha1 = handler.PrefixWrapper("ldap_hex_sha1", digests.hex_sha1, "{SHA}", "");pub const roundup_plaintext = handler.PrefixWrapper("roundup_plaintext", misc.plaintext, "{plaintext}", "");
/// The schemes this module defines, in the order `registry.identify` tries/// them. They come before `ldap_digests` in the registry, because `ldap_md5`/// and `ldap_sha1` claim every `{MD5}` and `{SHA}` string, hex or not.pub const schemes = .{ ldap_hex_md5, ldap_hex_sha1, roundup_plaintext };
comptime { for (schemes) |S| handler.check(S);}
test "hex in LDAP clothing" { const ctx: Context = .{ .io = testing.io, .gpa = testing.allocator }; // passlib 1.7.4: ldap_hex_md5 verifies either case of the hex digest. try testing.expect(try ldap_hex_md5.verify(ctx, "password", "{MD5}5f4dcc3b5aa765d61d8327deb882cf99")); try testing.expect(try ldap_hex_md5.verify(ctx, "password", "{MD5}5F4DCC3B5AA765D61D8327DEB882CF99")); try testing.expect(!ldap_hex_md5.identify("{MD5}X03MO1qnZdYdgyfeuILPmQ==")); try testing.expect(try roundup_plaintext.verify(ctx, "x", "{plaintext}x"));}