Hướng dẫn password_verify php w3schools - password_verify php w3schools

(Php 5> = 5.5.0, Php 7, Php 8)

password_verify - xác minh rằng mật khẩu khớp với bămVerifies that a password matches a hash

Sự mô tả

password_verify (chuỗi $password, chuỗi $hash): bool(string $password, string $hash): bool

Lưu ý rằng password_hash () trả về thuật toán, chi phí và muối như một phần của băm đã trả lại. Do đó, tất cả thông tin cần thiết để xác minh hàm băm được bao gồm trong đó. Điều này cho phép chức năng xác minh xác minh băm mà không cần lưu trữ riêng cho thông tin muối hoặc thuật toán.password_hash() returns the algorithm, cost and salt as part of the returned hash. Therefore, all information that's needed to verify the hash is included in it. This allows the verify function to verify the hash without needing separate storage for the salt or algorithm information.

Chức năng này là an toàn trước các cuộc tấn công thời gian.

Thông số

password

Mật khẩu của người dùng.

hash

Một hàm băm được tạo bởi password_hash ().password_hash().

Trả về giá trị

Trả về true nếu mật khẩu và băm phù hợp, hoặc false khác.true if the password and hash match, or false otherwise.

Ví dụ

Ví dụ #1 password_verify () Ví dụpassword_verify() example

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
0

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
1

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
2

Ví dụ trên sẽ xuất ra:

Xem thêm

  • password_hash () - Tạo mật khẩu băm
  • »& Nbsp; triển khai userland
  • natri_crypto_pwhash_str_verify () - xác minh rằng mật khẩu khớp với băm

Nicoswd ¶

9 năm trướcCreates a password hash

Lyo mi

6 năm trước(string $password, string|int|null

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
4, array
$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
5 = []
): string

Cloxy ¶

  • Martinstoeckli ¶ - Use the bcrypt algorithm (default as of PHP 5.5.0). Note that this constant is designed to change over time as new and stronger algorithms are added to PHP. For that reason, the length of the result from using this identifier can change over time. Therefore, it is recommended to store the result in a database column that can expand beyond 60 characters (255 characters would be a good choice).
  • Mike Robinson ¶ - Use the
    $2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
    
    8
    algorithm to create the hash. This will produce a standard crypt() compatible hash using the "$2y$" identifier. The result will always be a 60 character string, or false on failure.
  • 8 năm trước - Use the Argon2i hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support.
  • MS1 tại rdrecs dot com ¶ - Use the Argon2id hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support.

php dot net tại Marksim dot org ¶

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
7:

  • 2 năm trướcstring) - to manually provide a salt to use when hashing the password. Note that this will override and prevent a salt from being automatically generated.

    Ẩn danh ¶password_hash() for each password hashed. This is the intended mode of operation.

    hman ¶

    (Php 5> = 5.5.0, Php 7, Php 8)

  • password_hash - Tạo mật khẩu bămint) - which denotes the algorithmic cost that should be used. Examples of these values can be found on the crypt() page.

    Sự mô tả

password_hash (chuỗi $password, chuỗi | int | null

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
4, mảng
$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
5 = []): Chuỗi
Appropriate Cost Found: 10
0
and
Appropriate Cost Found: 10
1
:

  • Appropriate Cost Found: 10
    
    8 (int) - Bộ nhớ tối đa (tính bằng kibibyte) có thể được sử dụng để tính toán băm argon2. Mặc định là
    Appropriate Cost Found: 10
    
    9.int) - Maximum memory (in kibibytes) that may be used to compute the Argon2 hash. Defaults to
    Appropriate Cost Found: 10
    
    9
    .

  • Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
    
    0 (int) - Khoảng thời gian tối đa có thể mất để tính toán băm argon2. Mặc định là
    Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
    
    1.int) - Maximum amount of time it may take to compute the Argon2 hash. Defaults to
    Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
    
    1
    .

  • Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
    
    2 (int) - Số lượng luồng để sử dụng để tính toán băm argon2. Mặc định là
    Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
    
    3.int) - Number of threads to use for computing the Argon2 hash. Defaults to
    Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
    
    3
    .

    Cảnh báo

    Chỉ có sẵn khi PHP sử dụng libargon2, không phải với việc thực hiện libsodium.

Thông số

password

Mật khẩu của người dùng.

Thận trọng

Sử dụng

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
7 làm thuật toán, sẽ dẫn đến tham số password bị cắt theo chiều dài tối đa là 72 byte.
$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
7
as the algorithm, will result in the password parameter being truncated to a maximum length of 72 bytes.

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7

Một thuật toán mật khẩu hằng số biểu thị thuật toán sẽ sử dụng khi băm mật khẩu.

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
8

Một mảng kết hợp có chứa các tùy chọn. Xem các hằng số thuật toán mật khẩu để biết tài liệu về các tùy chọn được hỗ trợ cho mỗi thuật toán.

Nếu bị bỏ qua, một loại muối ngẫu nhiên sẽ được tạo ra và chi phí mặc định sẽ được sử dụng.

Trả về giá trị

Trả về mật khẩu băm.

Thuật toán đã sử dụng, chi phí và muối được trả lại như một phần của băm. Do đó, tất cả thông tin cần thiết để xác minh hàm băm được bao gồm trong đó. Điều này cho phép hàm password_verify () xác minh băm mà không cần lưu trữ riêng cho thông tin muối hoặc thuật toán.password_verify() function to verify the hash without needing separate storage for the salt or algorithm information.

Thay đổi

Phiên bảnSự mô tả
8.0.0 password_hash () không còn trả về false khi thất bại. no longer returns false on failure.
8.0.0 Tham số
Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 bây giờ là không thể.
7.4.0 Tham số
Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 mong đợi một chuỗi bây giờ, nhưng vẫn chấp nhận INTS cho khả năng tương thích ngược.string now, but still accepts ints for backward compatibility.
7.4.0 Phần mở rộng natri cung cấp một triển khai thay thế cho mật khẩu argon2.
7.3.0 Hỗ trợ mật khẩu argon2id bằng cách sử dụng
Appropriate Cost Found: 10
1 đã được thêm vào.
Appropriate Cost Found: 10
1
was added.
7.2.0 Hỗ trợ mật khẩu argon2i bằng cách sử dụng
Appropriate Cost Found: 10
0 đã được thêm vào.
Appropriate Cost Found: 10
0
was added.

Ví dụ

Ví dụ #1 password_hash () ví dụpassword_hash() example

$password4

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a

Ví dụ #2 password_hash () Cài đặt ví dụ về chi phí theo cách thủ côngpassword_hash() example setting cost manually

$password5

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K

Ví dụ #2 password_hash () Cài đặt ví dụ về chi phí theo cách thủ côngpassword_hash() example finding a good cost

$password6

$password7

$password8

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

Appropriate Cost Found: 10

Ví dụ #2 password_hash () Cài đặt ví dụ về chi phí theo cách thủ côngpassword_hash() example using Argon2i

$password9

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0

Ví dụ #2 password_hash () Cài đặt ví dụ về chi phí theo cách thủ công

Thận trọng

Sử dụng

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
7 làm thuật toán, sẽ dẫn đến tham số password bị cắt theo chiều dài tối đa là 72 byte.

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7

Một thuật toán mật khẩu hằng số biểu thị thuật toán sẽ sử dụng khi băm mật khẩu.:

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
8

Một mảng kết hợp có chứa các tùy chọn. Xem các hằng số thuật toán mật khẩu để biết tài liệu về các tùy chọn được hỗ trợ cho mỗi thuật toán.: Updates to supported algorithms by this function (or changes to the default one) must follow the following rules:

  • Nếu bị bỏ qua, một loại muối ngẫu nhiên sẽ được tạo ra và chi phí mặc định sẽ được sử dụng.
  • Trả về giá trị

Trả về mật khẩu băm.

  • Thuật toán đã sử dụng, chi phí và muối được trả lại như một phần của băm. Do đó, tất cả thông tin cần thiết để xác minh hàm băm được bao gồm trong đó. Điều này cho phép hàm password_verify () xác minh băm mà không cần lưu trữ riêng cho thông tin muối hoặc thuật toán.
  • Thay đổi
  • Phiên bản
  • Sự mô tả

password_hash () không còn trả về false khi thất bại.

Tham số

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 bây giờ là không thể.

$hash1

$hash2

$hash3

$hash4

$hash5

$hash6

$hash7

$hash8

$hash9

password0

password1

password2

password3

password4

Tham số

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 mong đợi một chuỗi bây giờ, nhưng vẫn chấp nhận INTS cho khả năng tương thích ngược.

Phần mở rộng natri cung cấp một triển khai thay thế cho mật khẩu argon2.

password5

password6

password7

password8

password9

hash0

password4

Hỗ trợ mật khẩu argon2id bằng cách sử dụng

Appropriate Cost Found: 10
1 đã được thêm vào.

Hỗ trợ mật khẩu argon2i bằng cách sử dụng

Appropriate Cost Found: 10
0 đã được thêm vào.

hash2

hash3

hash4

hash5

hash6

password4

Ví dụ

Phần mở rộng natri cung cấp một triển khai thay thế cho mật khẩu argon2.

hash8

hash9

true0

true1

Hỗ trợ mật khẩu argon2id bằng cách sử dụng

Appropriate Cost Found: 10
1 đã được thêm vào.

Phần mở rộng natri cung cấp một triển khai thay thế cho mật khẩu argon2.

true2

Hỗ trợ mật khẩu argon2id bằng cách sử dụng

Appropriate Cost Found: 10
1 đã được thêm vào.

Hỗ trợ mật khẩu argon2i bằng cách sử dụng

Appropriate Cost Found: 10
0 đã được thêm vào.

true3

true4

password4

Ví dụ

Tham số

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 bây giờ là không thể.

true6

true7

true8

true9

false0

false1

false2

false3

false4

false5

false6

password4

Tham số

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 mong đợi một chuỗi bây giờ, nhưng vẫn chấp nhận INTS cho khả năng tương thích ngược.

Phần mở rộng natri cung cấp một triển khai thay thế cho mật khẩu argon2.

false8

false9

password4

Hỗ trợ mật khẩu argon2id bằng cách sử dụng

Appropriate Cost Found: 10
1 đã được thêm vào.

Tham số

Argon2i hash: $argon2i$v=19$m=1024,t=2,p=2$YzJBSzV4TUhkMzc3d3laeg$zqU/1IN0/AogfP4cmSJI1vc8lpXRW9/S0sYY2i2jHT0
7 bây giờ là không thể.

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
01

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
02

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
03

password4

Hỗ trợ mật khẩu argon2id bằng cách sử dụng

Appropriate Cost Found: 10
1 đã được thêm vào.

2 năm trước

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
05

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
06

password4

hman ¶

3 năm trước

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
08

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
09

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
10

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
11

$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
12

password4