KScript ドキュメント
JA

言語

英語から自動翻訳されています。原文は英語です。

password のフィールドとメソッド

フィールドは、値についての単純な事実で、ドットを使い角括弧なしで読み取ります: $value.name。メソッドは引数を取るか処理を行い、-> で呼び出します: $value->name(arguments)。または、値をパイプで渡して呼び出します: $value |> name(arguments)。

KScript.Core から

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

パスワードの代わりに保存するハッシュです。argon2id(既定値)または bcrypt を指定でき、毎回新しいランダムな salt が使われます。
パラメーター受け取るもの
algorithm 省略可次のいずれかの語: argon2id|bcrypt
例
<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

パスワードが、これらのルールで ->strength() の検証を通過する場合に true を返します。
パラメーター受け取るもの
min 省略可int
max 省略可int
upper 省略可フラグ: upper または not upper
lower 省略可フラグ: lower または not lower
digit 省略可フラグ: digit または not digit
symbol 省略可フラグ: symbol または not symbol
common 省略可フラグ: common または not common
not 省略可string|string[]
score 省略可int

引数は名前で指定できます: ->is_strong(…, max: …, upper: …)。

例
<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

保存されたハッシュが、現在 ->hash() が使用している設定やアルゴリズムより弱い設定や別のアルゴリズムで作られている場合は true になります。ログイン成功後に置き換えるべきです。
パラメーター受け取るもの
hash 必須string
例
<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

パスワードの文字列です。別のサービスへのログインなど、パスワードを渡す目的でのみ使用してください。
例
<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

パスワードの推測されにくさ: { score (0〜4), label, ok, problems }。ルール: min length (8)、max、upper、lower、digit、symbol、common (true にすると有名なパスワードを拒否)、not (含んではいけない文字列)、score (合格とみなす最低スコア、3)。
パラメーター受け取るもの
min 省略可int
max 省略可int
upper 省略可フラグ: upper または not upper
lower 省略可フラグ: lower または not lower
digit 省略可フラグ: digit または not digit
symbol 省略可フラグ: symbol または not symbol
common 省略可フラグ: common または not common
not 省略可string|string[]
score 省略可int

引数は名前付きで指定できます: ->strength(…, max: …, upper: …)。

例
<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

入力されたパスワードが、保存されたハッシュの元になったものであれば真です。一致するかどうかにかかわらず、かかる時間は同じです。
パラメーター受け取るもの
hash 必須string
例
<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)

any のメソッド