php / php/doc-en

Add an example where the user string is a hash calculated from user submitted data

Open
#4,771 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

From manual page: https://php.net/function.hash-equals


I feel like the example can be slightly confusing because the user provides both the hash to check and values used to calculate the known correct hash. And I'm not sure having both values provided by the user is that common, in my experience these scenarios are pretty common:

  • user provides values that are hashed and checked against a known hash stored in DB
  • user provides a hash and this hash is compared with another hash calculated from stored values

I think it could be useful to add examples that cover these scenarios.

Maybe something like this for user provided values:

$knowCorrectHash = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae';

if (hash_equals($knowCorrectHash, hash('sha256', $_POST['value1'].':'.$_POST['value2'])) {
    echo "The provided values are correct.", PHP_EOL;
} else {
    echo "Wrong value.", PHP_EOL;
}

And for a user provided hash:

$correctHash = hash('sha256', 'foo');

if (hash_equals($correctHash, $_GET['hash']) {
    echo "This is the correct hash.", PHP_EOL;
} else {
    echo "Wrong hash.", PHP_EOL;
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the hash_equals manual page linked in the issue and inspect its current examples. Add an example covering user-submitted values checked against a known hash, and consider the second user-provided-hash scenario described in the issue. Done means the relevant documentation examples clearly cover the requested real-world cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.