|
Size: 2929
Comment: minor nits
|
← Revision 5 as of 2009-12-25 07:13:56 ⇥
Size: 2929
Comment: converted to 1.6 markup
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 6: | Line 6: |
| -- hd [[[DateTime(2004-08-10T04:59:36Z)]]] [[TableOfContents]] |
-- hd [<<DateTime(2004-08-10T04:59:36Z)>>] <<TableOfContents>> |
含有章节索引的中文 文章模板
-- hd [2004-08-10 04:59:36]
UnixMD5技巧
有很多情况下我们需要通过最简单的办法来使用一小段程序运算出Unix的密码MD5后的字符串出来。这个Tips将我们所知道的各种简单办法列出来,希望对大家有所帮助。
PHP
<?php $MyPassword = "pass"; echo crypt($MyPassword); ?>
Perl
perl -e 'print crypt("passwd","\$1\$randstr\$"),"\n"'
Python
pw=pass
python -c "import crypt;print crypt.crypt('"$pw"','py')"
C++
/*
* Copyright (c) Xin LI, 2004
* Copyright (c) Sina Mobile Corporation, 2004
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $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;
} else
cout << "Error: Can't allocate memory!";
cout << endl;
return (0);
}这个只是for FreeBSD 5。使用下面的命令进行编译后运行:
c++ -o maildb -O -pipe maildb.cpp -lcrypt
