2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2013 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/stdlib.h>
23 #include <ac/signal.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
33 * Password Test Program
36 static char *hash[] = {
37 #ifdef SLAP_AUTHPASSWD
50 static struct berval pw[] = {
51 { sizeof("secret")-1, "secret" },
52 { sizeof("binary\0secret")-1, "binary\0secret" },
57 main( int argc, char *argv[] )
60 struct berval *passwd;
61 #ifdef SLAP_AUTHPASSWD
65 bad.bv_val = "bad password";
66 bad.bv_len = sizeof("bad password")-1;
68 for( i= 0; hash[i]; i++ ) {
69 for( j = 0; pw[j].bv_len; j++ ) {
70 #ifdef SLAP_AUTHPASSWD
71 rc = lutil_authpasswd_hash( &pw[j],
72 &passwd, &salt, hash[i] );
76 passwd = lutil_passwd_hash( &pw[j], hash[i] );
81 printf("%s generate fail: %s (%d)\n",
82 hash[i], pw[j].bv_val, pw[j].bv_len );
87 #ifdef SLAP_AUTHPASSWD
88 rc = lutil_authpasswd( &pw[j], passwd, salt, NULL );
90 rc = lutil_passwd( passwd, &pw[j], NULL );
93 printf("%s (%d): %s (%d)\t(%d) %s\n",
94 pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
95 rc, rc == 0 ? "OKAY" : "BAD" );
97 #ifdef SLAP_AUTHPASSWD
98 rc = lutil_authpasswd( passwd, salt, &bad, NULL );
100 rc = lutil_passwd( passwd, &bad, NULL );
103 printf("%s (%d): %s (%d)\t(%d) %s\n",
104 bad.bv_val, bad.bv_len, passwd->bv_val, passwd->bv_len,
105 rc, rc != 0 ? "OKAY" : "BAD" );