diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-03-25 20:00:08 +0000 |
commit | 469bbcf0701e1eb8a6670c23145b0da87357e178 (patch) | |
tree | b5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/crypt.cpp | |
parent | ee1b79396076edc4e30aefb285fada03bb45e80d (diff) | |
download | libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2 libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip |
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/crypt.cpp')
-rw-r--r-- | src/stable/crypt.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/stable/crypt.cpp b/src/stable/crypt.cpp new file mode 100644 index 0000000..eb87479 --- /dev/null +++ b/src/stable/crypt.cpp | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/crypt.h" | ||
9 | #include "bu/md5.h" | ||
10 | #include "bu/base64.h" | ||
11 | #include "bu/membuf.h" | ||
12 | #include "bu/file.h" | ||
13 | |||
14 | Bu::String Bu::cryptPass( const Bu::String &sPass, const Bu::String &sSalt ) | ||
15 | { | ||
16 | Bu::Md5 md5; | ||
17 | Bu::MemBuf mbOut; | ||
18 | Bu::Base64 b64Out( mbOut ); | ||
19 | |||
20 | Bu::String::const_iterator i = sSalt.find('$'); | ||
21 | Bu::String sSaltSml = sSalt.getSubStr( sSalt.begin(), i ); | ||
22 | |||
23 | md5.addData( sPass ); | ||
24 | md5.addData( sSaltSml ); | ||
25 | md5.writeResult( b64Out ); | ||
26 | |||
27 | b64Out.stop(); | ||
28 | |||
29 | return sSaltSml + "$" + mbOut.getString(); | ||
30 | } | ||
31 | |||
32 | Bu::String Bu::cryptPass( const Bu::String &sPass ) | ||
33 | { | ||
34 | Bu::MemBuf mbSalt; | ||
35 | Bu::Base64 b64Salt( mbSalt ); | ||
36 | Bu::File fRand("/dev/urandom", Bu::File::Read ); | ||
37 | |||
38 | #define STR 6 | ||
39 | char buf[STR]; | ||
40 | fRand.read( buf, STR ); | ||
41 | b64Salt.write( buf, STR ); | ||
42 | |||
43 | b64Salt.stop(); | ||
44 | |||
45 | return cryptPass( sPass, mbSalt.getString() ); | ||
46 | } | ||
47 | |||