含有章节索引的中文 文章模板
-- hd [DateTime(2004-08-10T04:59:36Z)] TableOfContents
UnixMD5技巧
有很多情况下我们需要通过最简单的办法来使用一小段程序运算出Unix的密码MD5后的字符串出来。这个Tips将我们所知道的各种简单办法列出来,希望对大家有所帮助。
PHP
<?php $MyPassword = "pass"; echo crypt($MyPassword); ?>
Perl
perl -e 'print crypt("passwd","\$1\$randstr\$"),"\n"'
C++
/*
* Copyright (c) Xin LI, 2004
* Copyright (c) Sina Mobile Corporation, 2004
* All rights reserved.
*
* $Phantasm$
*/
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#include <unistd.h>
int main()
{
char *p = NULL;
char salt[] = "$1$12345678";
const char saltpattern[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";
string s;
cout << "Password: ";
cin >> s;
srand(123);
for(int i=3; i<11; i++)
salt[i] = saltpattern[rand() % ((sizeof saltpattern) -1)];
p = crypt(s.c_str(), salt);
if(p!=NULL) {
cout << "Hash: " << p << endl;
} else
cout << "Error: Can't allocate memory!" << endl;
}这个只是for bsd 5。使用下面的命令进行编译后运行:
c++ -o maildb -O -pipe maildb.cpp -lcrypt
