Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning code to response array to allow mapping to custom feedback strings #54

Open
hannahtinkler opened this issue Apr 9, 2021 · 0 comments

Comments

@hannahtinkler
Copy link

hannahtinkler commented Apr 9, 2021

As a developer
I want to be able to identify the reason for a low score using a concise string which will never change
So that I can communicate the feedback to my users in way which is more consistent with my application/brand tone of voice/localisation requirements

If a consistent response code was part of the response array, this would allow developers to map this to localisation maps and create validation messages which flow in a way that better suits their application. This is different to the feedback warnings currently returned which aren't guaranteed to not change in style/content (and so can't be mapped directly without risking breaking functionality with future updates).

Example:

[
  'password' =>'hannah2021',
  'guesses' => 2.13811968952E+20,
  'guesses_log10' =>20.330032012867,
  'sequence' => [...],
  'crack_times_seconds' => [...],
  'crack_times_display' => [...],
  'score' => 4,
  'feedback' => [
    'warning' => 'Dates are often easy to guess',
    'suggestion' => [...],
    'code' => 'guessable_dates',
  ],
  'calc_time' => 0.0208580493927,
]

Which would allow mapping to languages:

translate(sprintf('en.%s', $response['feedback']['code']));

Or mapping to custom messages:

private $map = [
    'guessable_dates' => 'Increase the complexity of your password or consider omitting dates from it.',
];


public function message()
{
    return $this->map[$response['feedback']['code']];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant