You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-07 17:42:53 +03:00
update generate_password() to allow length to be specified; update test
This commit is contained in:
@@ -832,14 +832,13 @@ function encode_header($string, $default_charset = "utf-8") {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
/**
|
||||||
// generate_password
|
* Generate a random password of $length characters.
|
||||||
// Action: Generates a random password
|
* @param int $length (optional, default: 12)
|
||||||
// Call: generate_password ()
|
* @return string
|
||||||
//
|
*
|
||||||
function generate_password() {
|
*/
|
||||||
// length of the generated password
|
function generate_password($length = 12) {
|
||||||
$length = 12;
|
|
||||||
|
|
||||||
// define possible characters
|
// define possible characters
|
||||||
$possible = "2345678923456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; # skip 0 and 1 to avoid confusion with O and l
|
$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->assertNotEquals($one, $two);
|
||||||
$this->assertNotEmpty($one);
|
$this->assertNotEmpty($one);
|
||||||
$this->assertNotEmpty($two);
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user