hash passwords

Roland Bauerschmidt rb at debian.org
Tue Jul 10 22:22:54 GMT 2001

I wrote a small patch against Samba 2.2 to get a tool (let's call it
hashsmbpasswd) to encrypt a given password as Samba does. I am using the
nt_lm_owf_gen function for that. This works fine for everything except 
of the NT hash which is everytime the same and logically doesn't work.
Maybe somebody sees the flaw in this.


#include <stdio.h>
#include <string.h>
#include "includes.h"

#define CMDLINE

 * hashsmbpasswd -- hashes a passwd and prints the entries as in
 * /etc/samba/smbpasswd

int main(int argc, char *argv[])
        char passwd[130];
        uchar nt_p16[16];
        uchar p16[16];
        int i;

#ifdef CMDLINE
        if(argc != 2) {
                fprintf(stderr, "Usage: %s password\n", argv[0]);

        strncpy(passwd, argv[1], 130);
        /* we don't want the password in process list */
        memset(argv[1], 0, strlen(argv[1]));
        fgets(passwd, 130, stdin);
        passwd[strlen(passwd)-1] = '\0';

        nt_lm_owf_gen(passwd, nt_p16, p16);

        for(i = 0; i < 16; i++)
                printf("%02X", nt_p16[i]);
        for(i = 0; i < 16; i++)
                printf("%02X", p16[i]);
        printf("[U          ]\n");
        printf("LCT-%08X\n", time(NULL));

Roland Bauerschmidt

More information about the samba-technical mailing list