src/User.php
public function setPersistToken($set = true)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$cookieParams = $this->cfg['persistCookie'];
		$return = null;
		if ($set) {
			$token = $this->genToken();	// raw binary
			$cookieParams['value'] = array(
				'username'	=> $this->user['username'],
				'token'		=> $token,
			);
			#$this->debug->log('value', $cookie['value']);
			Cookie::set($cookieParams);
			// store cookie / username combo in db
			$values = array(
				'userid'		=> $this->userid,
				'token_hash'	=> sha1($token),
			);
			$this->db->rowMan('persist_tokens', $values);
			$return = $cookieParams['value'];
		} elseif (isset($_COOKIE[ $cookieParams['name'] ])) {
			$vals = Cookie::get($cookieParams['name']);
			if (is_array($vals) && isset($vals['username']) && isset($vals['token'])) {
				// remove token from db
				// determine userid
				$userid = null;
				if (isset($this->user['username']) && $this->user['username'] === $vals['username']) {
					$userid = $this->userid;
				} else {
					$users = $this->search(array('username'=>$vals['username']));
					if ($users) {
						$userid = $users[0]['userid'];
					}
				}
				if ($userid) {
					$where = array(
						'userid'		=> $userid,
						'token_hash'	=> sha1($vals['token']),
					);
					$this->db->rowMan('persist_tokens', null, $where);
				}
				// remove cookie
				$cookieParams['value'] = null;
				Cookie::set($cookieParams);
			}
		}
		$this->debug->groupEnd();
		return $return;
	}
public function setPersistToken($set = true)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$cookieParams = $this->cfg['persistCookie'];
		$return = null;
		if ($set) {
			$token = $this->genToken();	// raw binary
			$cookieParams['value'] = array(
				'username'	=> $this->user['username'],
				'token'		=> $token,
			);
			#$this->debug->log('value', $cookie['value']);
			Cookie::set($cookieParams);
			// store cookie / username combo in db
			$values = array(
				'userid'		=> $this->userid,
				'token_hash'	=> sha1($token),
			);
			$this->db->rowMan('persist_tokens', $values);
			$return = $cookieParams['value'];
		} elseif (isset($_COOKIE[ $cookieParams['name'] ])) {
			$vals = Cookie::get($cookieParams['name']);
			if (is_array($vals) && isset($vals['username']) && isset($vals['token'])) {
				// remove token from db
				// determine userid
				$userid = null;
				if (isset($this->user['username']) && $this->user['username'] === $vals['username']) {
					$userid = $this->userid;
				} else {
					$users = $this->search(array('username'=>$vals['username']));
					if ($users) {
						$userid = $users[0]['userid'];
					}
				}
				if ($userid) {
					$where = array(
						'userid'		=> $userid,
						'token_hash'	=> sha1($vals['token']),
					);
					$this->db->rowMan('persist_tokens', null, $where);
				}
				// remove cookie
				$cookieParams['value'] = null;
				Cookie::set($cookieParams);
			}
		}
		$this->debug->groupEnd();
		return $return;
	}
public function setPersistToken ( $ set = true ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ cookieParams = $ this -> cfg [ 'persistCookie' ] ; $ return = null ; if ( $ set ) { $ token = $ this -> genToken ( ) ; // raw binary $ cookieParams [ 'value' ] = array ( 'username' => $ this -> user [ 'username' ] , 'token' => $ token , ) ; #$this->debug->log('value', $cookie['value']); Cookie :: set ( $ cookieParams ) ; // store cookie / username combo in db $ values = array ( 'userid' => $ this -> userid , 'token_hash' => sha1 ( $ token ) , ) ; $ this -> db -> rowMan ( 'persist_tokens' , $ values ) ; $ return = $ cookieParams [ 'value' ] ; } elseif ( isset ( $ _COOKIE [ $ cookieParams [ 'name' ] ] ) ) { $ vals = Cookie :: get ( $ cookieParams [ 'name' ] ) ; if ( is_array ( $ vals ) && isset ( $ vals [ 'username' ] ) && isset ( $ vals [ 'token' ] ) ) { // remove token from db // determine userid $ userid = null ; if ( isset ( $ this -> user [ 'username' ] ) && $ this -> user [ 'username' ] === $ vals [ 'username' ] ) { $ userid = $ this -> userid ; } else { $ users = $ this -> search ( array ( 'username' => $ vals [ 'username' ] ) ) ; if ( $ users ) { $ userid = $ users [ 0 ] [ 'userid' ] ; } } if ( $ userid ) { $ where = array ( 'userid' => $ userid , 'token_hash' => sha1 ( $ vals [ 'token' ] ) , ) ; $ this -> db -> rowMan ( 'persist_tokens' , null , $ where ) ; } // remove cookie $ cookieParams [ 'value' ] = null ; Cookie :: set ( $ cookieParams ) ; } } $ this -> debug -> groupEnd ( ) ; return $ return ; }
sets cookie
stores unsalted SHA1 hash in db

@param boolean $set true (false to remove cookie);

@return mixed set: array (cookie value), remove: null
sets cookie stores unsalted SHA1 hash in db