KScript documentation
FR

champs et méthodes de mot de passe

Un champ est une information simple sur la valeur, lue avec un point et sans crochets : $value.name. Une méthode prend des arguments ou effectue un traitement, et s'appelle avec -> : $value->name(arguments), ou avec la valeur transmise par un pipe : $value |> name(arguments).

Depuis KScript.Core

#password->hash(algorithm?: argon2id|bcrypt) → string

Un hachage à stocker à la place du mot de passe : argon2id (par défaut) ou bcrypt, avec un nouveau sel aléatoire à chaque fois.
ParamètrePrend
algorithm facultatifl'un de ces mots : argon2id|bcrypt
Exemple
<let name="pw" type="password" value="'correct horse battery staple'" />
<echo>{ $pw->hash()->starts_with('$argon2id$') }</echo>
$pw: password = 'correct horse battery staple'
echo $pw->hash()->starts_with('$argon2id$')

#password->is_strong(min?: int, max?: int, upper?: bool, lower?: bool, digit?: bool, symbol?: bool, common?: bool, not?: string|string[], score?: int) → bool

Vrai lorsque le mot de passe passe ->strength() avec ces règles.
ParamètrePrend
min facultatifint
max facultatifint
upper facultatifun indicateur : upper ou not upper
lower facultatifun drapeau : lower ou not lower
digit facultatifun drapeau : digit ou not digit
symbol facultatifun drapeau : symbol ou not symbol
common facultatifun drapeau : common ou not common
not facultatifstring|string[]
score facultatifint

Les arguments peuvent être nommés : ->is_strong(…, max: …, upper: …).

Exemple
<let name="pw" type="password" value="'correct horse battery staple'" />
<echo>{ $pw->is_strong(min: 12) }</echo>
$pw: password = 'correct horse battery staple'
echo $pw->is_strong(min: 12)

#password->needs_rehash(hash: string) → bool

Vrai lorsque le hachage stocké a été généré avec des paramètres plus faibles ou un autre algorithme que ceux utilisés actuellement par ->hash(), il doit donc être remplacé après une connexion réussie.
ParamètrePrend
hash obligatoirestring
Exemple
<let name="pw" type="password" value="'correct horse battery staple'" />
<echo>{ $pw->needs_rehash($pw->hash(algorithm: 'bcrypt')) }</echo>
$pw: password = 'correct horse battery staple'
echo $pw->needs_rehash($pw->hash(algorithm: 'bcrypt'))

#password->reveal() → string

Le texte du mot de passe. Ne l'utilisez que pour le transmettre, par exemple pour une connexion à un autre service.
Exemple
<let name="pw" type="password" value="'s3cret!'" />
<echo>$pw is { $pw->reveal()->count() } characters</echo>
$pw: password = 's3cret!'
echo "{ $pw } is { $pw->reveal()->count() } characters"

#password->strength(min?: int, max?: int, upper?: bool, lower?: bool, digit?: bool, symbol?: bool, common?: bool, not?: string|string[], score?: int) → map

La solidité du mot de passe : { score (de 0 à 4), label, ok, problems }. Règles : longueur minimale (8), maximale, majuscule, minuscule, chiffre, symbole, common (true rejette les mots de passe bien connus), not (texte qu'il ne doit pas contenir) et score (le score minimal accepté, 3).
ParamètrePrend
min facultatifint
max facultatifint
upper facultatifun indicateur : upper ou not upper
lower facultatifun drapeau : lower ou not lower
digit facultatifun drapeau : digit ou not digit
symbol facultatifun drapeau : symbol ou not symbol
common facultatifun drapeau : common ou not common
not facultatifstring|string[]
score facultatifint

Les arguments peuvent être nommés : ->strength(…, max: …, upper: …).

Exemple
<let name="pw" type="password" value="'password1'" />
<echo>{ $pw->strength(min: 12, symbol).problems }</echo>
$pw: password = 'password1'
echo $pw->strength(min: 12, symbol).problems

#password->verify(hash: string) → bool

Vrai lorsque c'est le mot de passe à partir duquel le hachage stocké a été créé. Le temps de calcul est le même, qu'il corresponde ou non.
ParamètrePrend
hash obligatoirestring
Exemple
<let name="pw" type="password" value="'correct horse battery staple'" />
<let name="stored" value="$pw->hash()" />
<echo>{ $pw->verify($stored) }</echo>
$pw: password = 'correct horse battery staple'
$stored = $pw->hash()
echo $pw->verify($stored)

Méthodes de tout type (any)