Unofficial SMF API Documentation

./Sources/Subs-Auth.php

setLoginCookie

function setLoginCookie(int $cookie_length, int $id, string $password = ''): void

Sets the SMF-style login cookie and session based on the id_member and password passed.

Type Parameter Description
int $cookie_length How many seconds the cookie should last. If negative, forces logout.
int $id The ID of the member to set the cookie for
string $password The hashed password
Integration hooks
integrate_cookie_data

setTFACookie

function setTFACookie(int $cookie_length, int $id, string $secret): void

Sets Two Factor Auth cookie

Type Parameter Description
int $cookie_length How long the cookie should last, in seconds
int $id The ID of the member
string $secret Should be a salted secret using hash_salt

url_parts

function url_parts(bool $local, bool $global): array

Get the domain and path for the cookie

Type Parameter Description
bool $local Whether we want local cookies
bool $global Whether we want global cookies

KickGuest

function KickGuest(): void

Throws guests out to the login screen when guest access is off.

InMaintenance

function InMaintenance(): void

Display a message about the forum being in maintenance mode.

adminLogin

function adminLogin(string $type = 'admin'): void

Question the verity of the admin by asking for his or her password.

Type Parameter Description
string $type What login type is this - can be ‘admin’ or ‘moderate’
Integration hooks
integrate_validateSession

adminLogin_outputPostVars

function adminLogin_outputPostVars(string $k, string $v): string

Used by the adminLogin() function.

if ‘value’ is an array, the function is called recursively.

Type Parameter Description
string $k The keys
string $v The values

construct_query_string

function construct_query_string(string $get): string

Properly urlencodes a string to be used in a query

Type Parameter Description
string $get  

findMembers

function findMembers(array $names, bool $use_wildcards = false, bool $buddies_only = false, int $max = 500): array

Finds members by email address, username, or real name.

Type Parameter Description
array $names The names of members to search for
bool $use_wildcards Whether to use wildcards. Accepts wildcards ? and * in the pattern if true
bool $buddies_only Whether to only search for the user’s buddies
int $max The maximum number of results

JSMembers

function JSMembers(): void

Called by index.php?action=findmember.

RequestMembers

function RequestMembers(): void

Outputs each member name on its own line.

resetPassword

function resetPassword(int $memID, string $username = null): void

Generates a random password for a user and emails it to them.

Type Parameter Description
int $memID The ID of the member
string $username The new username. If set, also checks the validity of the username
Integration hooks
integrate_reset_pass

validateUsername

function validateUsername(int $memID, string $username, bool $return_error = false, bool $check_reserved_name = true): ?array

Checks a username obeys a load of rules

Type Parameter Description
int $memID The ID of the member
string $username The username to validate
bool $return_error Whether to return errors
bool $check_reserved_name Whether to check this against the list of reserved names
Integration hooks
integrate_validate_username

validatePassword

function validatePassword(string $password, string $username, array $restrict_in = array()): ?string

Checks whether a password meets the current forum rules

Type Parameter Description
string $password The desired password
string $username The username
array $restrict_in An array of restricted strings that cannot be part of the password (email address, username, etc.)
Integration hooks
integrate_validatePassword

rebuildModCache

function rebuildModCache(): void

Quickly find out what moderation authority this user has

Integration hooks
integrate_mod_cache

smf_setcookie

function smf_setcookie(string $name, string $value = '', int $expire = 0, string $path = '', string $domain = '', bool $secure = null, bool $httponly = true, string $samesite = null): void

A wrapper for setcookie that gives integration hook access to it

Type Parameter Description
string $name  
string $value = ‘’
int $expire = 0
string $path = ‘’
string $domain = ‘’
bool $secure = false
bool $httponly = true
string $samesite = lax
Integration hooks
integrate_cookie

hash_password

function hash_password(string $username, string $password, int $cost = null): string

Hashes username with password

Type Parameter Description
string $username The username
string $password The unhashed password
int $cost The cost

hash_salt

function hash_salt(string $password, string $salt): string

Hashes password with salt and authentication secret. This is solely used for cookies.

Type Parameter Description
string $password The password
string $salt The salt

hash_verify_password

function hash_verify_password(string $username, string $password, string $hash): bool

Verifies a raw SMF password against the bcrypt’d string

Type Parameter Description
string $username The username
string $password The password
string $hash The hashed string

hash_length

function hash_length(): int

Returns the length for current hash

hash_benchmark

function hash_benchmark(float $hashTime = 0.2): int

Benchmarks the server to figure out an appropriate cost factor (minimum 9)

Type Parameter Description
float $hashTime Time to target, in seconds

hash_equals

function hash_equals(string $known_string, string $user_string): bool

A compatibility function for when PHP’s “hash_equals” function isn’t available

Type Parameter Description
string $known_string A known hash
string $user_string The hash of the user string

Suggest an edit to this page on GitHub