Merge branch 'pr/1316' into develop

Conflicts:
	classes/security/Password.class.php
This commit is contained in:
bnu 2015-03-10 11:20:43 +09:00
commit 6bdc099d92

View file

@ -275,6 +275,15 @@ class Password
{
return substr(bin2hex($output), 0, $length);
}
elseif($format === 'printable')
{
$salt = '';
for($i = 0; $i < $length; $i++)
{
$salt .= chr(33 + (crc32(sha1($i . $output)) % 94));
}
return $salt;
}
else
{
$salt = substr(base64_encode($output), 0, $length);
@ -283,6 +292,30 @@ class Password
}
}
/**
* @brief Generate a temporary password using the secure salt generator
* @param int $length The number of bytes to return
* @return string
*/
public function createTemporaryPassword($length = 16)
{
while(true)
{
$source = $this->createSecureSalt(128, 'printable');
$source = preg_replace('/[iIoOjl10\'"!?<>\(\)\{\}\[\]:;.,`\\\\]/', '', $source);
$source_length = strlen($source);
for($i = 0; $i < $source_length - $length; $i++)
{
$candidate = substr($source, $i, $length);
if(preg_match('/[a-z]/', $candidate) && preg_match('/[A-Z]/', $candidate) &&
preg_match('/[0-9]/', $candidate) && preg_match('/[!a-zA-Z0-9]/', $candidate))
{
return $candidate;
}
}
}
}
/**
* @brief Generate the PBKDF2 hash of a string using a salt
* @param string $password The password