allpy
changeset 32:e7c38612d3a7
"salt" generation providing random strings
author | boris <bnagaev@gmail.com> |
---|---|
date | Wed, 15 Sep 2010 08:51:30 +0400 |
parents | 9c00bbe94ff7 |
children | 58e6f26f0257 |
files | blocks3d-wt-widget.C blocks3d-wt.pro salt.C salt.h |
diffstat | 4 files changed, 27 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/blocks3d-wt-widget.C Wed Sep 15 01:40:07 2010 +0400 1.2 +++ b/blocks3d-wt-widget.C Wed Sep 15 08:51:30 2010 +0400 1.3 @@ -1,6 +1,7 @@ 1.4 1.5 #include "config.h" 1.6 #include "blocks3d-wt-widget.h" 1.7 +#include "salt.h" 1.8 1.9 #include <Wt/WText> 1.10 #include <Wt/WBreak>
2.1 --- a/blocks3d-wt.pro Wed Sep 15 01:40:07 2010 +0400 2.2 +++ b/blocks3d-wt.pro Wed Sep 15 08:51:30 2010 +0400 2.3 @@ -1,6 +1,7 @@ 2.4 TARGET = blocks3d-wt.exe 2.5 2.6 SOURCES += config.C 2.7 +SOURCES += salt.C 2.8 SOURCES += blocks3d-wt.C 2.9 SOURCES += blocks3d-wt-widget.C 2.10
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/salt.C Wed Sep 15 08:51:30 2010 +0400 3.3 @@ -0,0 +1,21 @@ 3.4 + 3.5 +#include "salt.h" 3.6 + 3.7 +std::string generateSalt() { 3.8 + /* Salt generation from glibc manual */ 3.9 + unsigned long seed[2]; 3.10 + char salt[] = "_1_........"; 3.11 + const char *const seedchars = 3.12 + "./0123456789ABCDEFGHIJKLMNOPQRST" 3.13 + "UVWXYZabcdefghijklmnopqrstuvwxyz"; 3.14 + 3.15 + /* Generate a (not very) random seed. */ 3.16 + seed[0] = time(NULL); 3.17 + seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000); 3.18 + 3.19 + /* Turn it into printable characters from `seedchars'. */ 3.20 + for (int i = 0; i < 8; i++) 3.21 + salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f]; 3.22 + 3.23 + return salt; 3.24 +}