KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

password 필드와 메서드

필드는 값에 관한 단순한 정보로, 대괄호 없이 점으로 읽어요: $value.name. 메서드는 인수를 받거나 작업을 수행하며, ->로 호출하거나 $value->name(arguments)처럼 값을 파이프로 넘겨서 호출해요: $value |> name(arguments).

KScript.Core에서 제공해요.

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

비밀번호 대신 저장할 해시입니다. argon2id(기본값) 또는 bcrypt이며, 매번 새 무작위 솔트를 씁니다.
매개변수받는 값
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 }. 규칙: 최소 길이(8), 최대 길이, 대문자, 소문자, 숫자, 기호, 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의 메서드