aboutsummaryrefslogtreecommitdiff
path: root/src/crypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypt.cpp')
-rw-r--r--src/crypt.cpp47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/crypt.cpp b/src/crypt.cpp
deleted file mode 100644
index eb87479..0000000
--- a/src/crypt.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
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
14Bu::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
32Bu::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