aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorJosh Woody <a_jelly_doughnut@phpbb.com>2010-08-19 09:11:36 -0500
committerJosh Woody <a_jelly_doughnut@phpbb.com>2010-08-19 09:11:36 -0500
commit25c579c00d25356afead09f13031e69e22f91324 (patch)
tree7466d1ef9e4d5c96f3369b5045d72796a219b746 /phpBB/includes/functions.php
parent46d2d97a378e1fc40359d4eff911d352c9b05c20 (diff)
parentc2b29c317f2d3bf41ed737c9eb3d49bce41ec432 (diff)
downloadforums-25c579c00d25356afead09f13031e69e22f91324.tar
forums-25c579c00d25356afead09f13031e69e22f91324.tar.gz
forums-25c579c00d25356afead09f13031e69e22f91324.tar.bz2
forums-25c579c00d25356afead09f13031e69e22f91324.tar.xz
forums-25c579c00d25356afead09f13031e69e22f91324.zip
Merge branch 'ticket/bantu/9612' into develop-olympus
* ticket/bantu/9612: [ticket/9612] Introduce new function gen_rand_string_friendly().
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 4c461b5ee8..6d2a6e685c 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -195,10 +195,27 @@ function set_config_count($config_name, $increment, $is_dynamic = false)
/**
* Generates an alphanumeric random string of given length
+*
+* @return string
*/
function gen_rand_string($num_chars = 8)
{
+ // [a, z] + [0, 9] = 36
+ return strtoupper(base_convert(unique_id(), 16, 36));
+}
+
+/**
+* Generates a user-friendly alphanumeric random string of given length
+* We remove 0 and O so users cannot confuse those in passwords etc.
+*
+* @return string
+*/
+function gen_rand_string_friendly($num_chars = 8)
+{
$rand_str = unique_id();
+
+ // Remove Z and Y from the base_convert(), replace 0 with Z and O with Y
+ // [a, z] + [0, 9] - {z, y} = [a, z] + [0, 9] - {0, o} = 34
$rand_str = str_replace(array('0', 'O'), array('Z', 'Y'), strtoupper(base_convert($rand_str, 16, 34)));
return substr($rand_str, 0, $num_chars);