mcornick (owner)

Revisions

gist: 36632 Download_button fork
public
Description:
a reasonably secure password maker
Public Clone URL: git://gist.github.com/36632.git
Embed All Files: show embed
pwm.js #
1
2
3
4
5
6
7
8
9
10
function pwm(length) {
  var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789'.split('');
  var password = '';
  for (i = 0; i < length; i++) {
    password += characters[Math.floor(Math.random() * characters.length)];
  }
  return password;
}
 
 
pwm.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env ruby
 
# minimum length for a password
MINIMUM_LENGTH = 4
# default length if not specified on command line
DEFAULT_LENGTH = 16
# sets of characters to use - don't use 0 and 1 to avoid confusion with O and I
CHARACTER_SETS = [('A'..'Z'),('a'..'z'),('2'..'9')]
 
# don't change this
characters = CHARACTER_SETS.collect{|set| set.collect{|character| character}}.flatten
 
length = (ARGV[0] || DEFAULT_LENGTH).to_i
raise ArgumentError, "length of #{length} is too short" unless length >= MINIMUM_LENGTH
 
password = (0..length-1).inject(''){|pw, n| pw + characters[rand(characters.length)] }
puts password