blob: 9111cdaee97fd2502b684332afb110a8a4bf8c92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include "bu/crypt.h"
#include "bu/md5.h"
#include "bu/base64.h"
#include "bu/membuf.h"
#include "bu/file.h"
Bu::FString Bu::cryptPass( const Bu::FString &sPass, const Bu::FString &sSalt )
{
Bu::Md5 md5;
Bu::MemBuf mbOut;
Bu::Base64 b64Out( mbOut );
Bu::FString::const_iterator i = sSalt.find('$');
Bu::FString sSaltSml = sSalt.getSubStr( sSalt.begin(), i );
md5.addData( sPass );
md5.addData( sSaltSml );
md5.writeResult( b64Out );
b64Out.stop();
return sSaltSml + "$" + mbOut.getString();
}
Bu::FString Bu::cryptPass( const Bu::FString &sPass )
{
Bu::MemBuf mbSalt;
Bu::Base64 b64Salt( mbSalt );
Bu::File fRand("/dev/urandom", Bu::File::Read );
#define STR 6
char buf[STR];
fRand.read( buf, STR );
b64Salt.write( buf, STR );
b64Salt.stop();
return cryptPass( sPass, mbSalt.getString() );
}
|