summaryrefslogtreecommitdiff
path: root/src/crypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypt.cpp')
-rw-r--r--src/crypt.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/crypt.cpp b/src/crypt.cpp
new file mode 100644
index 0000000..9111cda
--- /dev/null
+++ b/src/crypt.cpp
@@ -0,0 +1,40 @@
1#include "bu/crypt.h"
2#include "bu/md5.h"
3#include "bu/base64.h"
4#include "bu/membuf.h"
5#include "bu/file.h"
6
7Bu::FString Bu::cryptPass( const Bu::FString &sPass, const Bu::FString &sSalt )
8{
9 Bu::Md5 md5;
10 Bu::MemBuf mbOut;
11 Bu::Base64 b64Out( mbOut );
12
13 Bu::FString::const_iterator i = sSalt.find('$');
14 Bu::FString sSaltSml = sSalt.getSubStr( sSalt.begin(), i );
15
16 md5.addData( sPass );
17 md5.addData( sSaltSml );
18 md5.writeResult( b64Out );
19
20 b64Out.stop();
21
22 return sSaltSml + "$" + mbOut.getString();
23}
24
25Bu::FString Bu::cryptPass( const Bu::FString &sPass )
26{
27 Bu::MemBuf mbSalt;
28 Bu::Base64 b64Salt( mbSalt );
29 Bu::File fRand("/dev/urandom", Bu::File::Read );
30
31#define STR 6
32 char buf[STR];
33 fRand.read( buf, STR );
34 b64Salt.write( buf, STR );
35
36 b64Salt.stop();
37
38 return cryptPass( sPass, mbSalt.getString() );
39}
40