/** * Generates a random password and ecodes it * @param UserInterface $user * @return string */ public function setRandomPassword(UserInterface $user) { $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $pass = array(); //remember to declare $pass as an array $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache for ($i = 0; $i < 8; $i++) { $n = rand(0, $alphaLength); $pass[] = $alphabet[$n]; } $password = implode($pass); //turn the array into a string $user->setPlainPassword($password); $this->encodePassword($user); return $password; }