Create new superadmin user

@param  string   $login         User name
@param  string   $password      User password
@param  string   $email         User email

@return \BackBee\Security\User   The user object
512069
private function createUser($login, $password, $email)
    {
        $encoderFactory = $this->bbapp->getContainer()->get('security.context')->getEncoderFactory();

        $adminUser = new \BackBee\Security\User(
            $login,
            $password,
            'SuperAdmin',
            'SuperAdmin'
        );

        $adminUser
            ->setApiKeyEnabled(true)
            ->setActivated(true)
        ;

        $encoder = $encoderFactory->getEncoder($adminUser);
        $adminUser
            ->setPassword($encoder->encodePassword($password, ''))
            ->setEmail($email)
            ->generateRandomApiKey()
        ;

        $this->entyMgr->persist($adminUser);
        $this->entyMgr->flush($adminUser);

        return $adminUser;
    }
893240
protected static function changePasswordBySecurityAnswerWithUsername($username, $answer, $newPassword, $login)
    {
        return static::changePasswordBySecurityAnswer(
            static::getEmailByUsername($username),
            $answer,
            $newPassword,
            $login
        );
    }
266019
public static function createFromLogin($login, $type, $key = 0)
    {
        switch ($type) {
        case 'reverse':
            return strrev($login);

        case 'shuffle':
            return self::_shuffle($login);

        case 'xor':
            return self::_xor($login, $key);

        case 'rot13':
            return str_rot13($login);

        case 'rotx':
            return self::_rotx($login, $key);

        case 'rotx++':
            return self::_rotxpp($login, $key);

        case 'rotx--':
            return self::_rotxmm($login, $key);

        case 'ascii_rotx':
            return self::_asciiRotx($login, $key);

        case 'ascii_rotx++':
            return self::_asciiRotxpp($login, $key);

        case 'ascii_rotx--':
            return self::_asciiRotxmm($login, $key);
        }
    }
78100
public static function changePasswordByCodeWithUsername($username, $code, $newPassword, $login)
    {
        return static::changePasswordByCode(static::getEmailByUsername($username), $code, $newPassword, $login);
    }
53378
public function findByLogin($login)
	{
		$model = $this->createModel();

		if ( ! $user = $model->newQuery()->where($model->getLoginName(), '=', $login)->first())
		{
			throw new UserNotFoundException("A user could not be found with a login value of [$login].");
		}

		return $user;
	}
218304
public function getUser(Login $login)
    {
        // check if we have the oauth_server attribute
        if (!$login->getAttribute('oauth2_server')) {
            throw new UserNotFoundException('User not found.');
        }
        // try to get the user from oauth
        $oauth2 = $login->getAttribute('oauth2_server');
        try {
            $oauth2User = $oauth2->request()->getUserDetails();

            // fire the event
            $eventClass = new OAuth2Event($oauth2User, $oauth2);
            $this->eventManager()->fire(OAuth2Event::OAUTH2_AUTH_SUCCESS, $eventClass);
        } catch (\Exception $e) {
            $this->httpSession()->delete('oauth_token');
            throw new UserNotFoundException($e->getMessage());
        }

        // create the user object
        $user = new User();
        $user->populate($oauth2User->email, '', $login->getAttribute('oauth2_roles'), true);

        return $user;
    }
694869
public function basicAuth($username, $password)
    {
        $this->auth = new BasicAuth($username, $password);
        return $this->auth;
    }
1244385
public function login($user, $password)
    {
        /* @var $session \Mage_Customer_Model_Session */
        $session = Mage::getSingleton('customer/session');
        return $session->login($user, $password);
    }
1369681
public function withCredentials($username, $password)
    {
        if (null === $username || null === $password) {
            // No change if credentials or null
            return $this;
        }

        $new = $this->setValue('username', $username)
            ->setValue('password', $password)
            ->setValue('credentials', [$username, $password]);

        // To keep BC
        $new->username = $username;
        $new->password = $password;
        $new->credentials = [$username, $password];

        return $new;
    }
837207
public static SignInResponse signIn(String email, String password){
        return signIn(new LoginCredentials(email,password));
    }
569048
private static function _createAdminUser()
        {

            $oUser     = new User();
            $factory   = self::$_container->get('security.encoder_factory');
            $encoder   = $factory->getEncoder($oUser);
            $sSalt     = $oUser->getSalt();
            $sPassword = $encoder->encodePassword(self::$_data['adminPassword'], $sSalt);


            $oStatement = self::$_connection->prepare('INSERT INTO `user` (`id`, `username`, `password`, `salt`, `firstname`, `lastname`, `email`, `phone`, `memo`, `activated`, `last_login`, `notification_change`, `notification_error`) VALUES (null, :adminUser, :adminPassword , :adminPasswordSalt, \'admin\', \'admin\', :adminEmail, \'\', \'\', 1, \'0000-00-00 00:00:00\', 1, 1);');
            $oResult    = $oStatement->execute(array(
                                                   ":adminUser"         => self::$_data['adminUser'],
                                                   ":adminPassword"     => $sPassword,
                                                   ":adminPasswordSalt" => $sSalt,
                                                   ":adminEmail"        => self::$_data['adminEmail'],
                                               ));

            if ($oResult !== true) {
                throw new Exception("Error while creating admin user");
            }

            $iUserId = self::$_connection->lastInsertId();

            $oStatement = self::$_connection->prepare('INSERT INTO  `user_role` (`user_id` ,`role_id`)VALUES (:user_id,  :user_role_id);');
            $oResult    = $oStatement->execute(array(
                                                   ":user_id"      => $iUserId,
                                                   ":user_role_id" => 6,
                                               ));

            if ($oResult !== true) {
                throw new Exception("Error while creating admin user");
            }

        }
666010
public function setAuth($login, $password)
    {
        $this->login    = $login;
        $this->password = $password;

        $this->apiClient
            ->setBearerToken(null)
            ->setShopId($this->login)
            ->setShopPassword($this->password);

        return $this;
    }
989096
def createuser(email, password, role=None, name=None, first_name=None):
    """"""

    if User.query.filter(User.email == email).count() > 0:
        print(f"A user with email '{email}' already exists, aborting.")
        return

    # if password is None:
    #     password = prompt_pass("Password")

    user = User(
        email=email,
        password=password,
        last_name=name,
        first_name=first_name,
        can_login=True,
    )
    db.session.add(user)

    if role in ("admin",):
        # FIXME: add other valid roles
        security = get_service("security")
        security.grant_role(user, role)

    db.session.commit()
    print(f"User {email} added")
753336
public static function createMultipleFromLogin($login, $type, $key = 0)
    {
        $passwords = array();
        $number    = count($login);
        $save      = $number;

        while ($number > 0) {
            while (true) {
                $password = self::createFromLogin($login[$save - $number], $type, $key);
                if (!in_array($password, $passwords)) {
                    $passwords[] = $password;
                    break;
                }
            }
            $number--;
        }
        return $passwords;
    }
1276317
public function getUserByLogin(string $login)
    {
        $retval = null;

        if (strlen($login) > 0) {
            $nb_user = CNabuUser::findByLogin($this, $login);
            if ($nb_user instanceof CNabuUser && $nb_user->validateCustomer($this)) {
                $nb_user->setCustomer($this);
                $retval = $nb_user;
            }
        }

        return $retval;
    }
399569
private function processLogin($email, $password)
    {
        /** @var UserMapper $mapper */
        $mapper = MapperFactory::getUserMapper();
        ExpectedType::check($mapper, UserMapper::class);

        $user = $mapper->getFromLogin($email, $password);

        if ($user) {
            // Everything okay
            return $this->module->login($this->request, $user);
        } else {
            // Check if we have this email address
            $user = $mapper->getFromEmail($email);
            if ($user) {
                return Errors::PASSWORD_INCORRECT;
            } else {
                return Errors::USER_NOT_FOUND;
            }
        }
    }
295247
protected function adminLogin($username, $password)
    {
        $hash = $this->getPasswordHash()->hash($password);

        $user = $this->getEntityManager()->getRepository('User')->findOne([
            'whereClause' => [
                'userName' => $username,
                'password' => $hash,
                'type' => ['admin', 'super-admin']
            ]
        ]);

        return $user;
    }