in reply to Keys beside keys on keyboards
$neighbors = { a => { q => 1, w => 1, s => 1, z => 1, }, s => { a => 1, w => 1, e => 1, d => 1, x => 1, z => 1, }, etc. }
This hash would be specific to the type of keyboard being used.
You could then traverse, character-by-character, through the password to see if three successive finds occur in the neighbors hash for each letter traversed.
#!/usr/bin/perl use strict; use warnings; my $neighbors = { a => { q => 1, w => 1, s => 1, z => 1, }, s => { a => 1, w => 1, e => 1, d => 1, x => 1, z => 1, }, }; my $password = "asasas"; my $counter = 1; my $lastchar = ""; for my $char (split(//, $password)) { print $char, "\n"; $counter++ if $neighbors->{$lastchar}->{$char}; $lastchar = $char; last if $counter == 3; } if ($counter == 3) { print "Invalid password"; # make them enter a new password... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Keys beside keys on keyboards
by thezip (Vicar) on Nov 07, 2006 at 02:22 UTC |