1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 05:47:53 +00:00

fix the maximum generate password

This commit is contained in:
nishiki 2014-01-08 20:22:33 +01:00
parent c590c672a1
commit 929a645071
3 changed files with 12 additions and 3 deletions

View file

@ -35,7 +35,7 @@ en:
import: "Import item since a CSV file"
force: "Force an action"
format: "Change the display items format by an alternative format"
generate_password: "Generate a random password (default 8 characters, max 63 characters)"
generate_password: "Generate a random password (default 8 characters)"
help: "Show this help message"
form:
add:

View file

@ -35,7 +35,7 @@ fr:
import: "Importe des éléments depuis un fichier au format CSV"
force: "Force une action, l'action ne demandera pas de confirmation"
format: "Change le format d'affichage des éléments par un alternatif"
generate_password: "Génére un mot de passe aléatoire (défaut 8 caractères, max 63 caractères)"
generate_password: "Génére un mot de passe aléatoire (défaut 8 caractères)"
help: "Affiche ce message d'aide"
form:
add:

View file

@ -360,9 +360,18 @@ class MPW
def self.generatePassword(length=8)
if length.to_i <= 0
length = 8
else
length = length.to_i
end
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(length.to_i).join
result = ''
while length > 62 do
result << ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(62).join
length -= 62
end
result << ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(length).join
return result
#return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]-%w(0 1 I O l i o)).sample(length).join
end