update generate_password() to allow length to be specified; update test

pull/181/head
David Goodwin 6 years ago
parent 7388a7ca62
commit 7282928e6d

@ -832,14 +832,13 @@ function encode_header($string, $default_charset = "utf-8") {
//
// generate_password
// Action: Generates a random password
// Call: generate_password ()
//
function generate_password() {
// length of the generated password
$length = 12;
/**
* Generate a random password of $length characters.
* @param int $length (optional, default: 12)
* @return string
*
*/
function generate_password($length = 12) {
// define possible characters
$possible = "2345678923456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; # skip 0 and 1 to avoid confusion with O and l

@ -11,5 +11,18 @@ class GeneratePasswordTest extends PHPUnit_Framework_TestCase {
$this->assertNotEquals($one, $two);
$this->assertNotEmpty($one);
$this->assertNotEmpty($two);
$this->assertEquals(12, strlen($one));
}
public function testLength() {
$one = generate_password(1);
$ten = generate_password(10);
$this->assertNotEquals($one, $ten);
$this->assertNotEmpty($one);
$this->assertNotEmpty($ten);
$this->assertEquals(10, strlen($ten));
$this->assertEquals(1, strlen($one));
}
}

Loading…
Cancel
Save