mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
Add method to create a password that includes all character classes
This commit is contained in:
parent
8da6ddcfe8
commit
8e0b310e2a
1 changed files with 24 additions and 0 deletions
|
|
@ -292,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
|
* @brief Generate the PBKDF2 hash of a string using a salt
|
||||||
* @param string $password The password
|
* @param string $password The password
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue