]> git.mxchange.org Git - friendica.git/commitdiff
guid functions
authorFriendika <info@friendika.com>
Sun, 7 Aug 2011 23:56:26 +0000 (16:56 -0700)
committerFriendika <info@friendika.com>
Sun, 7 Aug 2011 23:56:26 +0000 (16:56 -0700)
boot.php
include/text.php
mod/register.php

index d5adbd7cf17de729924fd538bee2034619e1db8f..3bdbe2db2a72b51663e6dd0b639ca171bdac2106 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -610,12 +610,12 @@ function check_config(&$a) {
 }}
 
 
-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));
index d53a2ceb9ae7905a554af14cabd4e3d8a14598c1..2973836023825c14d4907c025bfc163122b9f2df 100644 (file)
@@ -19,11 +19,11 @@ function replace_macros($s,$r) {
 }}
 
 
-// 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));
 }}
 
 /**
@@ -878,7 +878,7 @@ function return_bytes ($size_str) {
     }
 }}
 
-function generate_guid() {
+function generate_user_guid() {
        $found = true;
        do {
                $guid = substr(random_string(),0,16);
index a8d81f1f6bb1360dfa548bea16cc284fbc648425..fbd21a567f7e513f805810cdf9e4e56e6e7edb56 100644 (file)
@@ -201,7 +201,7 @@ function register_post(&$a) {
        $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),