public static function authenticate($email, $password) { $authenticator = new MemberAuthenticator(); if ($user = $authenticator->authenticate(['Password' => $password, 'Email' => $email])) { // create session $session = ApiSession::create(); $session->User = $user; $session->Token = JwtAuth::generate_token($user); return $session; } }
public static function authenticate($email, $password) { // auth $authenticator = new \MemberAuthenticator(); if ($user = $authenticator->authenticate(['Password' => $password, 'Email' => $email])) { $user->logIn(); $user = DataObject::get(Config::inst()->get('BaseRestController', 'Owner'))->byID($user->ID); // create session $session = ApiSession::create(); $session->User = $user; $session->Token = AuthFactory::generate_token($user); return $session; } }
public static function authenticate($email, $password) { $authenticator = new MemberAuthenticator(); if ($user = $authenticator->authenticate(['Password' => $password, 'Email' => $email])) { // create session $session = ApiSession::create(); $session->User = $user; $session->Token = AuthFactory::generate_token($user); // save session $cache = SS_Cache::factory('rest_cache'); $cache->save(json_encode(['token' => $session->Token, 'user' => $session->User->ID]), $session->Token); return $session; } }
/** * Require basic authentication. Will request a username and password if none is given. * * Used by {@link Controller::init()}. * * @param string $realm * @param string|array $permissionCode * @return Member $member */ static function requireLogin($realm, $permissionCode) { if (!Security::database_is_ready() || Director::is_cli()) { return true; } if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null); if ($member) { $authenticated = true; } } // If we've failed the authentication mechanism, then show the login form if (!isset($authenticated)) { header("WWW-Authenticate: Basic realm=\"{$realm}\""); header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized'); if (isset($_SERVER['PHP_AUTH_USER'])) { echo _t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised"); } else { echo _t('BasicAuth.ENTERINFO', "Please enter a username and password."); } die; } if (!Permission::checkMember($member->ID, $permissionCode)) { header("WWW-Authenticate: Basic realm=\"{$realm}\""); header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized'); if (isset($_SERVER['PHP_AUTH_USER'])) { echo _t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator."); } die; } return $member; }
/** * Get the most recent posts on a blog. */ function getRecentPosts($blogid, $username, $password, $numberOfPosts) { $member = MemberAuthenticator::authenticate(array('Email' => $username, 'Password' => $password)); // TODO Throw approriate error. if (!$member) { die; } $posts = DataObject::get('BlogEntry', '"ParentID" = ' . (int) $blogid, '"Date" DESC'); $res = array(); $postsSoFar = 0; foreach ($posts as $post) { if (!$post->canEdit($member)) { continue; } $parr = array(); $parr['title'] = $post->Title; $parr['link'] = $post->AbsoluteLink(); $parr['description'] = $post->Content; $parr['postid'] = (int) $post->ID; $res[] = $parr; if (++$postsSoFar >= $numberOfPosts) { break; } } return $res; }
/** * Attempt to login * @param {stdClass} $data Data passed from ActionScript * @return {array} Returns a standard response array */ public function login($data) { $response = CodeBank_ClientAPI::responseBase(); $response['login'] = true; //Try to login $member = MemberAuthenticator::authenticate(array('Email' => $data->user, 'Password' => $data->pass)); if ($member instanceof Member && $member->ID != 0 && Permission::check('CODE_BANK_ACCESS', 'any', $member)) { try { $member->logIn(); $ipAgrement = CodeBankConfig::CurrentConfig()->IPAgreement; //Get preferences $prefs = new stdClass(); $prefs->heartbeat = $member->UseHeartbeat; //Set the response to HELO $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.WELCOME_USER', '_Welcome {user}', array('user' => htmlentities($member->Name))); //Set the message to "Welcome ...." $response['data'] = array('id' => Member::currentUserID(), 'hasIPAgreement' => !empty($ipAgrement), 'preferences' => $prefs, 'isAdmin' => Permission::check('ADMIN') !== false, 'displayName' => trim($member->Name) == '' ? $member->Email : trim($member->Name)); } catch (Exception $e) { //Something happend on the server $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.SERVER_ERROR', '_Server error has occured, please try again later'); } } else { //Bad username/pass combo $response['status'] = 'EROR'; $response['message'] = _t('CodeBankAPI.INVALID_LOGIN', '_Invalid Login'); } return $response; }
/** * Require basic authentication. Will request a username and password if none is given. * * Used by {@link Controller::init()}. * * @throws SS_HTTPResponse_Exception * * @param string $realm * @param string|array $permissionCode Optional * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the * session log-in if those credentials are disabled. * @return Member $member */ public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true) { $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test(); if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) { return true; } /* * Enable HTTP Basic authentication workaround for PHP running in CGI mode with Apache * Depending on server configuration the auth header may be in HTTP_AUTHORIZATION or * REDIRECT_HTTP_AUTHORIZATION * * The follow rewrite rule must be in the sites .htaccess file to enable this workaround * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] */ $authHeader = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) ? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] : null); $matches = array(); if ($authHeader && preg_match('/Basic\\s+(.*)$/i', $authHeader, $matches)) { list($name, $password) = explode(':', base64_decode($matches[1])); $_SERVER['PHP_AUTH_USER'] = strip_tags($name); $_SERVER['PHP_AUTH_PW'] = strip_tags($password); } $member = null; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null); } if (!$member && $tryUsingSessionLogin) { $member = Member::currentUser(); } // If we've failed the authentication mechanism, then show the login form if (!$member) { $response = new SS_HTTPResponse(null, 401); $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\""); if (isset($_SERVER['PHP_AUTH_USER'])) { $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised")); } else { $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password.")); } // Exception is caught by RequestHandler->handleRequest() and will halt further execution $e = new SS_HTTPResponse_Exception(null, 401); $e->setResponse($response); throw $e; } if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) { $response = new SS_HTTPResponse(null, 401); $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\""); if (isset($_SERVER['PHP_AUTH_USER'])) { $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator.")); } // Exception is caught by RequestHandler->handleRequest() and will halt further execution $e = new SS_HTTPResponse_Exception(null, 401); $e->setResponse($response); throw $e; } return $member; }
/** * @param Controller $controller * @param string $back_url * @return Form */ public static function buildLoginForm(Controller $controller, $back_url = '') { if (!defined('OPENSTACKID_ENABLED') || OPENSTACKID_ENABLED == false) { $form = MemberAuthenticator::get_login_form($controller); return $form; } else { $back_url = OpenStackIdCommon::cleanBackUrl($back_url); $form = new Form($controller, 'OpenStackIdLoginForm', $fields = new FieldList(), $actions = new FieldList(array(new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in"))))); $form->addExtraClass('form-fieldless'); $form->setFormAction("/Security/login?BackURL={$back_url}"); $form->setFormMethod('post'); return $form; } }
public function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() { Config::inst()->update('PasswordEncryptor', 'encryptors', array('crc32' => array('PasswordEncryptor_PHPHash' => 'crc32'))); $field = Member::config()->unique_identifier_field; $member = new Member(); $member->{$field} = '*****@*****.**'; $member->PasswordEncryption = "crc32"; $member->Password = "******"; $member->write(); $data = array('Email' => $member->{$field}, 'Password' => 'mypassword'); MemberAuthenticator::authenticate($data); $member = DataObject::get_by_id('Member', $member->ID); $this->assertEquals($member->PasswordEncryption, "crc32"); $result = $member->checkPassword('mypassword'); $this->assertTrue($result->valid()); }
/** * Require basic authentication. Will request a username and password if none is given. * * Used by {@link Controller::init()}. * * @throws SS_HTTPResponse_Exception * * @param string $realm * @param string|array $permissionCode Optional * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the * session log-in if those credentials are disabled. * @return Member $member */ public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true) { $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test(); if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) { return true; } $matches = array(); if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) { list($name, $password) = explode(':', base64_decode($matches[1])); $_SERVER['PHP_AUTH_USER'] = strip_tags($name); $_SERVER['PHP_AUTH_PW'] = strip_tags($password); } $member = null; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null); } if (!$member && $tryUsingSessionLogin) { $member = Member::currentUser(); } // If we've failed the authentication mechanism, then show the login form if (!$member) { $response = new SS_HTTPResponse(null, 401); $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\""); if (isset($_SERVER['PHP_AUTH_USER'])) { $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised")); } else { $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password.")); } // Exception is caught by RequestHandler->handleRequest() and will halt further execution $e = new SS_HTTPResponse_Exception(null, 401); $e->setResponse($response); throw $e; } if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) { $response = new SS_HTTPResponse(null, 401); $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\""); if (isset($_SERVER['PHP_AUTH_USER'])) { $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator.")); } // Exception is caught by RequestHandler->handleRequest() and will halt further execution $e = new SS_HTTPResponse_Exception(null, 401); $e->setResponse($response); throw $e; } return $member; }
/** * executed if there are no valdation errors on submit * Form data is saved in session * * @param SS_HTTPRequest $data contains the frameworks form data * @param Form $form not used * @param array $formData contains the modules form data * * @return array to be rendered in the controller * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 27.06.2014 */ protected function submitSuccess($data, $form, $formData) { $emailAddress = $formData['emailaddress']; $password = $formData['password']; // get customers data $user = Member::get()->filter('Email', $formData['emailaddress'])->first(); if ($user) { $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password)); if ($customer) { //transfer cart positions from an anonymous user to the one logging in $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer(); if ($anonymousCustomer) { if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) { //delete registered customers cart positions if ($customer->getCart()->SilvercartShoppingCartPositions()) { foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) { $position->delete(); } } //add anonymous positions to the registered user foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) { $customer->getCart()->SilvercartShoppingCartPositions()->add($position); } } $anonymousCustomer->logOut(); $anonymousCustomer->delete(); } $customer->logIn(); $customer->write(); if ($this->Controller()->redirectedTo() == '') { $myAccountHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartMyAccountHolder"); $this->Controller()->redirect($myAccountHolder->RelativeLink()); } } else { $this->addMessage(_t('SilvercartPage.CREDENTIALS_WRONG', 'Your credentials are incorrect.')); Requirements::customScript('jQuery(document).ready(function(){ $("#silvercart-quicklogin-form").slideDown(); });'); return $this->submitFailure($data, $form); } } else { $this->addMessage(_t('SilvercartPage.CREDENTIALS_WRONG')); Requirements::customScript('jQuery(document).ready(function(){ $("#silvercart-quicklogin-form").slideDown(); });'); return $this->submitFailure($data, $form); } }
/** * executed if there are no valdation errors on submit * Form data is saved in session * * @param SS_HTTPRequest $data contains the frameworks form data * @param Form $form not used * @param array $formData contains the modules form data * * @return array to be rendered in the controller * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 27.06.2014 */ protected function submitSuccess($data, $form, $formData) { $emailAddress = $formData['emailaddress']; $password = $formData['password']; // get customers data $user = Member::get()->filter('Email', $formData['emailaddress'])->first(); if ($user) { $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password)); if ($customer) { //transfer cart positions from an anonymous user to the one logging in $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer(); if ($anonymousCustomer) { if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) { //delete registered customers cart positions if ($customer->getCart()->SilvercartShoppingCartPositions()) { foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) { $position->delete(); } } //add anonymous positions to the registered user foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) { $customer->getCart()->SilvercartShoppingCartPositions()->add($position); } } $anonymousCustomer->logOut(); $anonymousCustomer->delete(); } $customer->logIn(); $customer->write(); $myAccountHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartMyAccountHolder"); $this->controller->redirect($myAccountHolder->RelativeLink()); } else { $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG', 'Your credentials are incorrect.'))); return $this->submitFailure($data, $form); } } else { $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.EMAIL_NOT_FOUND', 'This Email address could not be found.'))); return $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG'))); } }
/** * Attempt to find and authenticate member if possible from the given data * * @param array $data * @param Form $form * @param bool &$success Success flag * @return Member Found member, regardless of successful login * @throws RestUserException */ protected static function authenticate_member($data, $form, &$success) { if (!empty($data['Token'])) { /** @var Member $member */ $member = null; // First check that the token is valid if (self::validate_token($data['Token'], $data['AuthService'], $data['UserID'])) { // Second, check that the Member exists /** @var SocialIdentity $identity */ $identity = SocialIdentity::get()->filter(['AuthService' => $data['AuthService'], 'UserID' => $data['UserID']])->first(); if ($identity) { $member = $identity->Member(); $success = true; return $member; } throw new RestUserException("User not found", 401, 401); } else { throw new RestUserException("Invalid access token", 401, 401); } } else { return parent::authenticate_member($data, $form, $success); } }
/** * Return the member currently logged in using basicuath * @todo Move this into the core BasicAuth class */ function getBasicAuthMember() { if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null); return $member; } }
/** * Login a user into the Framework and generates API token * Only works if the token owner is a Member * * @param SS_HTTPRequest $request HTTP request containing 'email' & 'pwd' vars * @return array login result with token */ public function login(SS_HTTPRequest $request) { $response = array(); if ($this->tokenConfig['owner'] === 'Member') { $email = $request->requestVar('email'); $pwd = $request->requestVar('pwd'); $member = false; if ($email && $pwd) { $member = MemberAuthenticator::authenticate(array('Email' => $email, 'Password' => $pwd)); if ($member) { $tokenData = $this->generateToken(); $tokenDBColumn = $this->tokenConfig['DBColumn']; $expireDBColumn = $this->tokenConfig['expireDBColumn']; $member->{$tokenDBColumn} = $tokenData['token']; $member->{$expireDBColumn} = $tokenData['expire']; $member->write(); $member->login(); } } if (!$member) { $response['result'] = false; $response['message'] = 'Authentication fail.'; $response['code'] = self::AUTH_CODE_LOGIN_FAIL; } else { $response['result'] = true; $response['message'] = 'Logged in.'; $response['code'] = self::AUTH_CODE_LOGGED_IN; $response['token'] = $tokenData['token']; $response['expire'] = $tokenData['expire']; $response['userID'] = $member->ID; } } return $response; }
/** * Try to authenticate the user * * @param array Submitted data * @return Member Returns the member object on successful authentication * or NULL on failure. */ public function performLogin($data) { if ($member = MemberAuthenticator::authenticate($data, $this)) { $firstname = Convert::raw2xml($member->FirstName); Session::set("Security.Message.message", sprintf(_t('Member.WELCOMEBACK', "Welcome Back, %s"), $firstname)); Session::set("Security.Message.type", "good"); $member->LogIn(isset($data['Remember'])); return $member; } else { return null; } }
public function testDefaultAdminLockOut() { Config::inst()->update('Member', 'lock_out_after_incorrect_logins', 1); Config::inst()->update('Member', 'lock_out_delay_mins', 10); SS_Datetime::set_mock_now('2016-04-18 00:00:00'); $controller = new Security(); $form = new Form($controller, 'Form', new FieldList(), new FieldList()); // Test correct login MemberAuthenticator::authenticate(array('Email' => 'admin', 'Password' => 'wrongpassword'), $form); $this->assertTrue(Member::default_admin()->isLockedOut()); $this->assertEquals(Member::default_admin()->LockedOutUntil, '2016-04-18 00:10:00'); }
protected function authenticate() { if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { return false; } if ($member = Member::currentMember()) { return $member; } $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null); if ($member) { $member->LogIn(false); return $member; } else { return false; } }
/** * Returns the default log-in form. * * @todo Check if here should be returned just the default log-in form or * all available log-in forms (also OpenID...) */ public function LoginForm() { return MemberAuthenticator::get_login_form($this); }
/** * Method to authenticate an user * * @param array $RAW_data Raw data to authenticate the user * @param Form $form Optional: If passed, better error messages can be * produced by using * {@link Form::sessionMessage()} * @return bool|Member Returns FALSE if authentication fails, otherwise * the member object */ public static function authenticate($RAW_data, Form $form = null) { return parent::authenticate($RAW_data, $form); }
/** * Action to do a login * * @param SS_HTTPRequest $request Request to check for product data * @param bool $doRedirect Redirect after setting search settings? * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 30.06.2014 */ public function doLogin(SS_HTTPRequest $request, $doRedirect = true) { $postVars = $request->postVars(); $emailAddress = $postVars['emailaddress']; $password = $postVars['password']; $member = Member::get()->filter('Email', $emailAddress)->first(); if ($member instanceof Member && $member->exists()) { $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password)); if ($customer instanceof Member && $customer->exists()) { //transfer cart positions from an anonymous user to the one logging in $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer(); if ($anonymousCustomer) { if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->count() > 0) { //delete registered customers cart positions if ($customer->getCart()->SilvercartShoppingCartPositions()) { foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) { $position->delete(); } } //add anonymous positions to the registered user foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) { $customer->getCart()->SilvercartShoppingCartPositions()->add($position); } } $anonymousCustomer->logOut(); $anonymousCustomer->delete(); } $customer->logIn(); $customer->write(); } else { $messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG'))); } } else { $messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG'))); } $this->redirectBack($postVars['redirect_to']); }
/** * executed if there are no valdation errors on submit * Form data is saved in session * * @param SS_HTTPRequest $data contains the frameworks form data * @param Form $form not used * @param array $formData contains the modules form data * * @return void * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 27.06.2014 */ public function submitSuccess($data, $form, $formData) { $emailAddress = $formData['Email']; $password = $formData['Password']; // get customers data $user = Member::get()->filter('Email', $emailAddress)->first(); if ($user) { $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password)); if ($customer) { //transfer cart positions from an anonymous user to the one logging in $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer(); if ($anonymousCustomer) { if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) { //delete registered customers cart positions if ($customer->getCart()->SilvercartShoppingCartPositions()) { foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) { $position->delete(); } } //add anonymous positions to the registered user foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) { $customer->getCart()->SilvercartShoppingCartPositions()->add($position); } } $anonymousCustomer->logOut(); $anonymousCustomer->delete(); } $customer->logIn(); $customer->write(); $this->getController()->redirect($this->getController()->Link()); } else { $this->addErrorMessage('Password', _t('SilvercartPage.PASSWORD_WRONG', 'This user does not exist.')); return $this->submitFailure($data, $form); } } else { $this->addErrorMessage('Email', _t('SilvercartPage.USER_NOT_EXISTING', 'This user does not exist.')); return $this->submitFailure($data, $form); } }
/** * Test that the default admin can be authenticated */ public function testDefaultAdmin() { // Make form $controller = new Security(); $form = new Form($controller, 'Form', new FieldList(), new FieldList()); // Test correct login $result = MemberAuthenticator::authenticate(array('Email' => 'admin', 'Password' => 'password'), $form); $this->assertNotEmpty($result); $this->assertEquals($result->Email, Security::default_admin_username()); $this->assertEmpty($form->Message()); // Test incorrect login $form->clearMessage(); $result = MemberAuthenticator::authenticate(array('Email' => 'admin', 'Password' => 'notmypassword'), $form); $this->assertEmpty($result); $this->assertEquals('The provided details don't seem to be correct. Please try again.', $form->Message()); $this->assertEquals('bad', $form->MessageType()); }
/** * Authenticates the user. * * @return bool|Member * * @author Sascha Koehler <*****@*****.**> * @since 2013-02-22 */ protected function authenticate() { $serverAuth = $this->checkServerLoginCredentials(); if (!$serverAuth) { if ($member = Member::currentMember()) { return $member; } else { return false; } } $member = MemberAuthenticator::authenticate(array('Email' => $serverAuth['PHP_AUTH_USER'], 'Password' => $serverAuth['PHP_AUTH_PW']), null); if ($member) { $member->LogIn(false); return $member; } else { return false; } }
/** * Try to authenticate the user * * @param array Submitted data * @return Member Returns the member object on successful authentication * or NULL on failure. */ public function performLogin($data) { if ($member = MemberAuthenticator::authenticate($data, $this)) { $member->LogIn(isset($data['Remember'])); return $member; } else { $this->extend('authenticationFailed', $data); return null; } }