Skip to content

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

@hannahtinkler

Description

@hannahtinkler

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']];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions