Generates a new random password

@access protected
@return string
180662
protected function generateRandomPassword()
    {
        $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+*=-_/()!?[]{}';
        $password = array();
        $alphabetLength = strlen($alphabet) - 1;
        
        for ($i = 0; $i < 10; $i++) {
            $charIndex = mt_rand(0, $alphabetLength);
            $password[] = $alphabet[$charIndex];
        }
        
        $password = implode('', $password);
        
        if (!preg_match('/\d/', $password)) {
            $password = mt_rand(0, 9) . $password . mt_rand(0, 9);
        }
        
        return $password;
    }
1217324
public function forgePasswordToken()
	{
		$password_token       = Str::random(128);
		$this->password_token = $password_token;

		if ($this->save()) {
			return $password_token;
		}
	}
1169536
public function resetPassword() : string {
		$newPass = bin2hex(random_bytes(20));
		$newHash = password_hash($newPass, PASSWORD_BCRYPT);

		$stmt = $this->db->prepare(
			"UPDATE accounts SET pw_hash=? WHERE id=?;"
		);
		$stmt->bind_param("si", $newHash, $this->id);
		$stmt->execute();
		$this->db->commit();
		$this->pwHash = $newHash;

		$this->sessionManager->wipeLoginSession();
		return $newPass;
	}
540323
public static function genToken(){
        $str = md5(uniqid(mt_rand(), true));
        $uuid  = substr($str,0,8) . '-';
        $uuid .= substr($str,8,4) . '-';
        $uuid .= substr($str,12,4) . '-';
        $uuid .= substr($str,16,4) . '-';
        $uuid .= substr($str,20,12);
        return $uuid;
    }
638080
public function getNewPasswordElement()
    {
        $element = $this->getElement($this->_newPasswordFieldName);

        if (! $element) {
            // Field new password
            $element = new \Zend_Form_Element_Password($this->_newPasswordFieldName);
            $element->setLabel($this->_('New password'));
            $element->setAttrib('size', 40);
            $element->setRequired(true);
            $element->setRenderPassword(true);
            $element->addValidator(new \Gems_User_Validate_NewPasswordValidator($this->user));

            $validator = new \MUtil_Validate_IsConfirmed($this->_newPasswordFieldName, $this->_('Repeat password'));
            $validator->setMessage(
                    $this->_("Must be the same as %fieldDescription%."),
                    \MUtil_Validate_IsConfirmed::NOT_SAME
                    );
            $element->addValidator($validator);

            $this->addElement($element);
        }

        return $element;
    }
215213
public function actionGenerate()
	{
		$passwordList = \App::$domain->tool->password->generate();
		$text = implode(SPC, $passwordList);
		Output::line();
		Output::pipe('Generated passwords');
		Output::autoWrap($text);
		Output::pipe();
		Output::line();
	}
190084
public function generatesecuretoken()
    {
        $generator = Injector::inst()->create('SilverStripe\\Security\\RandomGenerator');
        $token = $generator->randomToken('sha1');
        $body = <<<TXT
Generated new token. Please add the following code to your YAML configuration:

Security:
  token: $token

TXT;
        $response = new HTTPResponse($body);
        return $response->addHeader('Content-Type', 'text/plain');
    }
1361807
public static function _randomPassword ($length = self::DEFAULT_PASSWORD_LENGTH, $charset = self::DEFAULT_PASSWORD_CHARACTERS)
	{
		
		// Set password variable
		
		$password	= '';

		// Set i to the password length
		
		$i = $length;

		// Loop until the password is the desired length
		
		while ($i > 0)
		{
			
			// Choose a random character from the charset
			
			$char = $charset[mt_rand (0, strlen ($charset) -1)];

			// Make sure that the first character of the password is a number or letter
			
			if ($password == '' && !preg_match('/[0-9A-Za-z]/', $char))
			{
				continue;
			}
			
			// Add the character to the password
			
			$password .= $char;

			// Decrement rounds
			
			$i--;

		}

		// Return the password
		
		return $password;

	}
968611
public function passwordAction()
    {
        $minLength = $this->container->getParameter('phlexible_user.password.min_length');

        $generator = new PasswordGenerator();
        $password = $generator->create($minLength, PasswordGenerator::TYPE_UNPRONOUNCABLE);

        return new JsonResponse(
            [
                'password' => $password,
                'success' => true,
            ]
        );
    }
1226170
public static function random_password($length = 8)
	{
		$genpass = '';
		$salt = "abchefghjkmnpqrstuvwxyz0123456789";

		srand((double)microtime()*1000000);

		$i = 0;

		while ($i < $length)
		{
			$num = rand() % 33;
			$tmp = substr($salt, $num, 1);
			$genpass = $genpass . $tmp;
			$i++;
		}

		return $genpass;
	}
245973
public function genUid() {
    $rand = $this['crypt/rand'];

    $hex = bin2hex($rand->Bytes(32));
    $str = substr($hex,0,16) . '-' . substr($hex,16,8) . '-' . substr($hex,24,8) . '-' . substr($hex,32,8) . '-' . substr($hex,40,24);
    return $str;
  }
995263
public static function random_string($length) {
        $key = '';
        $keys = array_merge(range(0, 9), range('a', 'z'));

        for ($i = 0; $i < $length; $i++) {
            $key .= $keys[array_rand($keys)];
        }

        return $key;
    }
1346506
protected static function generateSalt(): string
    {
        $result = '';

        static::validateSaltMinLength();

        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $poolSize = strlen($pool);
        for ($i = 0; $i < static::$saltMinLength; $i++) {
            $result .= $pool[rand(0, $poolSize - 1)];
        }

        return $result;
    }
237106
public function generateToken() {
		if( !isset($_SESSION[self::SESSION_KEY][$this->name]) ) {
			$_SESSION[self::SESSION_KEY][$this->name]	= array();
		}
		$TOKEN_SESSION = &$_SESSION[self::SESSION_KEY][$this->name];
		do {
			$token = generatePassword(static::$TOKEN_LENGTH);
		} while( isset($TOKEN_SESSION[$token]) );
		if( count($TOKEN_SESSION) >= $this->maxToken ) {
			array_shift($TOKEN_SESSION);
		}
		$TOKEN_SESSION[$token]	= 0;
		return $token;
	}
800306
private function generate()
    {
        $characters = config('promocodes.characters');
        $mask = config('promocodes.mask');
        $promocode = '';
        $random = [];

        for ($i = 1; $i <= $this->length; $i++) {
            $character = $characters[rand(0, strlen($characters) - 1)];
            $random[] = $character;
        }

        shuffle($random);
        $length = count($random);

        $promocode .= $this->getPrefix();

        for ($i = 0; $i < $length; $i++) {
            $mask = preg_replace('/\*/', $random[$i], $mask, 1);
        }

        $promocode .= $mask;
        $promocode .= $this->getSuffix();

        return $promocode;
    }
713815
public function generate($length = 16, $alpha = 0.6, $numeric = 0.2, $other = 0.2)
    {
        $chars = array();

        //~ Alphabetic characters
        for ($index = 0, $max = ceil($alpha * $length); $index < $max; $index++) {
            if ((bool) rand(0, 1)) {
                $char = rand(65, 90); // Upper
            } else {
                $char = rand(97, 122); // Lower
            }

            $chars[] = chr($char);
        }

        //~ Alphabetic characters
        for ($index = 0, $max = ceil($numeric * $length); $index < $max; $index++) {
            $char    = rand(48, 57); // Number
            $chars[] = chr($char);
        }

        //~ Other printable chars
        for ($index = 0, $max = ceil($other * $length); $index < $max; $index++) {

            switch ((int) rand(1, 4)) {
                case 1:
                    $char = rand(33, 47);
                    break;
                case 2:
                    $char = rand(58, 64);
                    break;
                case 3:
                    $char = rand(91, 96);
                    break;
                case 4:
                default:
                    $char = rand(123, 126);
                    break;
            }

            $chars[] = chr($char);
        }

        shuffle($chars);

        $this->password = implode('', array_slice($chars, 0, 16));

        return $this;
    }
868694
public function generate()
    {
        $alphabet = '';

        if (strpos($this->available_sets, 'l') !== false) {
            $alphabet .= $this->lowercase;
        }

        if (strpos($this->available_sets, 'u') !== false) {
            $alphabet .= $this->uppercase;
        }

        if (strpos($this->available_sets, 'd') !== false) {
            $alphabet .= $this->numbers;
        }

        if (strpos($this->available_sets, 's') !== false) {
            $alphabet .= $this->special_chars;
        }

        $alphamax = strlen($alphabet) - 1;

        if ($alphamax < 1) {
            throw new PasswordException('Invalid alphabet');
        }

        $this->password = '';

        for ($i = 0; $i < $this->length; ++$i) {
            $this->password .= $alphabet[random_int(0, $alphamax)];
        }

        return $this->password;
    }