Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

generate_resource_access_key()

Description

Generates an external access key for a resource, allowing specified access to a user or group.

This function creates a unique access key and stores it in the database along with
information about the resource, the user, the type of access granted,
expiration date, email, and user group. It also hashes the share password if provided.

Parameters

ColumnTypeDefaultDescription
$resource int The resource reference for which the access key is being generated.
$userref int The user reference for the user to whom access is granted.
$access int The level of access granted (e.g., full access, restricted).
$expires string|null The expiration date of the access key, formatted as 'Y-m-d'.
$email string The email address associated with the user receiving the access key.
$group string "" The user group associated with the access, defaults to the current user group if not specified.
$sharepwd string "" The share password, if any, used to secure access.

Return

string|bool Returns the generated access key on success, or false if permissions are insufficient.

Location

include/resource_functions.php lines 6592 to 6617

Definition

 
function generate_resource_access_key($resource,$userref,$access,$expires,$email,$group="",$sharepwd="")
        {
        if(
checkperm("noex"))
            {
            
// Shouldn't ever happen, but catch in case not already checked
            
return false;
            }

        global 
$userref,$usergroup$scramble_key;
        if (
$group=="" || !checkperm("x")) {$group=$usergroup;} # Default to sharing with the permission of the current usergroup if not specified OR no access to alternative group selection.
        
$k=substr(md5(time()),0,10);
        
ps_query("insert into external_access_keys(resource,access_key,user,access,expires,email,date,usergroup,password_hash) values (?, ?, ?, ?, ?, ?,now(), ?, ?);",
            [
            
'i'$resource,
            
's'$k,
            
'i'$userref,
            
'i'$access,
            
's', ((!validateDatetime($expires'Y-m-d'))? null $expires),
            
's'$email,
            
'i'$group,
            
's', (($sharepwd != "" && $sharepwd != "(unchanged)") ? hash('sha256'$k $sharepwd $scramble_key) : null)
            ]
        );
        
hook("generate_resource_access_key","",array($resource,$k,$userref,$email,$access,$expires,$group));
        return 
$k;
        }

This article was last updated 17th November 2024 15:05 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.