src/snac/server/database/DBUser.php
/**
     * Generate API Key for user
     *
     * Generates an API Key for the given user and returns it.  API key generation
     * is handled by the APIKeyGenerator, but the expiration time is handled by Postgres
     * directly by default values (currently 1 year).  That could be overridden.
     *
     * The first 8 characters of the key are maintained as the label to show to the user.
     * The rest of the key is stored only as an encrypted password, meaning that it cannot
     * be recovered for the user.  If a key is lost, a new one must be generated.
     *
     * WARNING: This method sets the 'key' value in the associative array to the generated
     * key.  This SHOULD NOT be logged on production in any capacity.  It should NEVER be
     * saved to the database or anywhere else, but only returned to the user once.
     *
     * @param \snac\data\User $user The user
     *
     * @return \snac\data\APIKey The generated API key WITH THE CLEAR-TEXT KEY INSIDE!
     */
Generate API Key for user
Generates an API Key for the given user and returns it.  API key generation
is handled by the APIKeyGenerator, but the expiration time is handled by Postgres
directly by default values (currently 1 year).  That could be overridden.

The first 8 characters of the key are maintained as the label to show to the user.
The rest of the key is stored only as an encrypted password, meaning that it cannot
be recovered for the user.  If a key is lost, a new one must be generated.

This method sets the 'key' value in the associative array to the generated
key.  This SHOULD NOT be logged on production in any capacity.  It should NEVER be
saved to the database or anywhere else, but only returned to the user once.

@param \snac\data\User $user The user


Generate API Key for user Generates an API Key for the given user and returns it . API key generation is handled by the APIKeyGenerator but the expiration time is handled by Postgres directly by default values ( currently 1 year ) . That could be overridden . The first 8 characters of the key are maintained as the label to show to the user . The rest of the key is stored only as an encrypted password meaning that it cannot be recovered for the user . If a key is lost a new one must be generated . This method sets the ' key ' value in the associative array to the generated key . This SHOULD NOT be logged on production in any capacity . It should NEVER be saved to the database or anywhere else but only returned to the user once . @param \ snac \ data \ User $user The user
public function generateUserAPIKey($user) {
        $key = \snac\server\authentication\APIKeyGenerator::generateKey($user->getUserID());
        $label = substr($key, 0, 8);
        $keyData = $this->sql->saveUserKey($user->getUserID(), $key, $label);
        if (isset($keyData["key"])) {
            $obj = new \snac\data\APIKey();
            $obj->setKey($key);
            $obj->setLabel($label);
            $obj->setExpires($keyData["expires"]);
            $obj->setGenerated($keyData["generated"]);
            return $obj;
        }
        return null;
    }
public function generateUserAPIKey ( $ user ) { $ key = \ snac \ server \ authentication \ APIKeyGenerator :: generateKey ( $ user -> getUserID ( ) ) ; $ label = substr ( $ key , 0 , 8 ) ; $ keyData = $ this -> sql -> saveUserKey ( $ user -> getUserID ( ) , $ key , $ label ) ; if ( isset ( $ keyData [ " key " ] ) ) { $ obj = new \ snac \ data \ APIKey ( ) ; $ obj -> setKey ( $ key ) ; $ obj -> setLabel ( $ label ) ; $ obj -> setExpires ( $ keyData [ " expires " ] ) ; $ obj -> setGenerated ( $ keyData [ " generated " ] ) ; return $ obj ; } return null ; }
Generate API Key for user
 Generates an API Key for the given user and returns it.
Generate API Key for user Generates an API Key for the given user and returns it .