]> git.sur5r.net Git - openldap/blob - libraries/liblutil/ptest.c
Add simple password test program.
[openldap] / libraries / liblutil / ptest.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/stdlib.h>
12
13 #include <ac/ctype.h>
14 #include <ac/signal.h>
15 #include <ac/socket.h>
16 #include <ac/string.h>
17 #include <ac/time.h>
18
19 #include <lber.h>
20
21 #include "lutil.h"
22
23
24 char *hash[] = {
25         "{SMD5}", "{SSHA}",
26         "{MD5}", "{SHA}",
27         NULL
28 };
29
30 static struct berval pw[] = {
31         { sizeof("secret")-1,                   "secret" },
32         { sizeof("binary\0secret")-1,   "secret\0binary" },
33         { 0, NULL }
34 };
35
36 int
37 main( int argc, char *argv[] )
38 {
39         int i, j, rc;
40         struct berval *passwd;
41
42         for( i= 0; hash[i]; i++ ) {
43                 for( j = 0; pw[j].bv_len; j++ ) {
44                         passwd = lutil_passwd_generate( &pw[j], hash[i] );
45                         rc = lutil_passwd( passwd, &pw[j], NULL );
46
47                         printf("%s (%d): %s (%d) %s\n",
48                                 pw[j].bv_val, pw[j].bv_len, passwd->bv_val, passwd->bv_len,
49                                 rc == 0 ? "OKAY" : "BAD" );
50                 }
51         }
52         return EXIT_SUCCESS;
53 }