Share a single Linux ioctl helper fo setting interface up/down
[hostap-gosc2009.git] / hostapd / nt_password_hash.c
blob839802a744c5df861d2538204a6e6b2898bffbcf
1 /*
2 * hostapd - Plaintext password to NtPasswordHash
3 * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
17 #include "common.h"
18 #include "crypto/ms_funcs.h"
21 int main(int argc, char *argv[])
23 unsigned char password_hash[16];
24 size_t i;
25 char *password, buf[64], *pos;
27 if (argc > 1)
28 password = argv[1];
29 else {
30 if (fgets(buf, sizeof(buf), stdin) == NULL) {
31 printf("Failed to read password\n");
32 return 1;
34 buf[sizeof(buf) - 1] = '\0';
35 pos = buf;
36 while (*pos != '\0') {
37 if (*pos == '\r' || *pos == '\n') {
38 *pos = '\0';
39 break;
41 pos++;
43 password = buf;
46 if (nt_password_hash((u8 *) password, strlen(password), password_hash))
47 return -1;
48 for (i = 0; i < sizeof(password_hash); i++)
49 printf("%02x", password_hash[i]);
50 printf("\n");
52 return 0;