}}
-function get_guid() {
- $exists = true;
+function get_guid($size=16) {
+ $exists = true; // assume by default that we don't have a unique guid
do {
- $s = random_string(16);
+ $s = random_string($size);
$r = q("select id from guid where guid = '%s' limit 1", dbesc($s));
- if(! results($r))
+ if(! count($r))
$exists = false;
} while($exists);
q("insert into guid ( guid ) values ( '%s' ) ", dbesc($s));
}}
-// random hash, 64 chars
+// random hex string, 64 chars max
if(! function_exists('random_string')) {
-function random_string() {
- return(hash('sha256',uniqid(rand(),true)));
+function random_string($size = 64) {
+ return(substr(hash('sha256',uniqid(rand(),true)),0,$size));
}}
/**
}
}}
-function generate_guid() {
+function generate_user_guid() {
$found = true;
do {
$guid = substr(random_string(),0,16);
$r = q("INSERT INTO `user` ( `guid`, `username`, `password`, `email`, `openid`, `nickname`,
`pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked` )
VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
- dbesc(generate_guid()),
+ dbesc(generate_user_guid()),
dbesc($username),
dbesc($new_password_encoded),
dbesc($email),