/** * test login function * * @param String $userId * @param String $password * @return String */ public function login($userId, $password) { if ($userId == 'user' && $password == 'userPassword') { AmfphpAuthentication::addRole('user'); return 'user'; } if ($userId == 'admin' && $password == 'adminPassword') { AmfphpAuthentication::addRole('admin'); return 'admin'; } throw new Exception("bad credentials"); }
/** * sign in * @param string $username * @param string $password * @return boolean */ public function signIn($username, $password) { $pdo = MySQLUtil::getConnection(); // hash the password $password = DBUtils::hashPassword($password); $tsql = "SELECT ur.name AS user_role, u.* FROM users AS u"; $tsql .= " INNER JOIN user_roles AS ur ON (ur.id = u.user_role_id)"; $tsql .= " WHERE u.username = :username AND u.password = :pass"; $stmt = $pdo->prepare($tsql); $stmt->bindParam(':username', $username, PDO::PARAM_STR); $stmt->bindParam(':pass', $password, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_OBJ); if ($result) { AmfphpAuthentication::addRole($result->user_role); unset($result->password); return $result; } else { return false; } }
/** * test clear session info */ public function testClearSessionInfo() { AmfphpAuthentication::addRole('bla'); AmfphpAuthentication::clearSessionInfo(); $this->assertFalse(isset($_SESSION[AmfphpAuthentication::SESSION_FIELD_ROLES])); }