Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/e7c38612d3a7
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:16:48 2012
Кодировка:

# HG changeset patch
# User boris
# Date 1284526290 -14400
# Node ID e7c38612d3a732238eaa288dd85e88b53708eb3f
# Parent 9c00bbe94ff77d2bb860b22d3c5c717180ee6b82
"salt" generation providing random strings

diff -r 9c00bbe94ff7 -r e7c38612d3a7 blocks3d-wt-widget.C
--- a/blocks3d-wt-widget.C Wed Sep 15 01:40:07 2010 +0400
+++ b/blocks3d-wt-widget.C Wed Sep 15 08:51:30 2010 +0400
@@ -1,6 +1,7 @@

#include "config.h"
#include "blocks3d-wt-widget.h"
+#include "salt.h"

#include
#include
diff -r 9c00bbe94ff7 -r e7c38612d3a7 blocks3d-wt.pro
--- a/blocks3d-wt.pro Wed Sep 15 01:40:07 2010 +0400
+++ b/blocks3d-wt.pro Wed Sep 15 08:51:30 2010 +0400
@@ -1,6 +1,7 @@
TARGET = blocks3d-wt.exe

SOURCES += config.C
+SOURCES += salt.C
SOURCES += blocks3d-wt.C
SOURCES += blocks3d-wt-widget.C

diff -r 9c00bbe94ff7 -r e7c38612d3a7 salt.C
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/salt.C Wed Sep 15 08:51:30 2010 +0400
@@ -0,0 +1,21 @@
+
+#include "salt.h"
+
+std::string generateSalt() {
+ /* Salt generation from glibc manual */
+ unsigned long seed[2];
+ char salt[] = "_1_........";
+ const char *const seedchars =
+ "./0123456789ABCDEFGHIJKLMNOPQRST"
+ "UVWXYZabcdefghijklmnopqrstuvwxyz";
+
+ /* Generate a (not very) random seed. */
+ seed[0] = time(NULL);
+ seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
+
+ /* Turn it into printable characters from `seedchars'. */
+ for (int i = 0; i < 8; i++)
+ salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
+
+ return salt;
+}
diff -r 9c00bbe94ff7 -r e7c38612d3a7 salt.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/salt.h Wed Sep 15 08:51:30 2010 +0400
@@ -0,0 +1,4 @@
+
+#include
+
+std::string generateSalt();