passw 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/passw +10 -0
- data/lib/passw.rb +68 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0f665744f6b6f8a587b38f5e93b30c7c3a117e3
|
4
|
+
data.tar.gz: 98a02a75d2b2c2bde31c393aeafa07b56c3581e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af15ebe940d3ada7dcbd3e25c121d26ad35a42245c551a379e67040cf25f3d28199d6e1c8910c9dd858c5778190b1e6710c17ea42f9666cbcbe9d29b98e0eb55
|
7
|
+
data.tar.gz: 5c230f6818efbf09bf54c3b42a67793e925f677d4286f2226abaaa7c230fdad8191be526b0aae6d4de7b69d5cb912c3e8534389c6bfe14ecb49b8e769fcbe780
|
data/bin/passw
ADDED
data/lib/passw.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Passw
|
2
|
+
# Generate a password with the sepecified options
|
3
|
+
# Params:
|
4
|
+
# +length+:: the length of the password
|
5
|
+
# +options+:: a hash defining the attributes for the password
|
6
|
+
def self.generate(length, options = {})
|
7
|
+
defaults = {
|
8
|
+
lowercase: true, # Allow lower case characters
|
9
|
+
uppercase: true, # Allow uppercase characters
|
10
|
+
symbols: true, # Allow symbols
|
11
|
+
numbers: true, # Allow numbers
|
12
|
+
duplicates: true # Allow characters to be duplicated (less secure if true)
|
13
|
+
}
|
14
|
+
|
15
|
+
defaults.merge!(options)
|
16
|
+
|
17
|
+
buffer = []
|
18
|
+
|
19
|
+
buffer += lowercase if defaults[:lowercase]
|
20
|
+
buffer += uppercase if defaults[:uppercase]
|
21
|
+
buffer += symbols if defaults[:symbols]
|
22
|
+
buffer += numbers if defaults[:numbers]
|
23
|
+
|
24
|
+
base = []
|
25
|
+
|
26
|
+
buffer_length = buffer.length
|
27
|
+
|
28
|
+
(0...length.to_i).each do |i|
|
29
|
+
if defaults[:duplicates]
|
30
|
+
base << buffer[srand % buffer_length]
|
31
|
+
else
|
32
|
+
loop do
|
33
|
+
candidate = buffer[srand % buffer_length]
|
34
|
+
|
35
|
+
if !base.include? candidate
|
36
|
+
base << candidate
|
37
|
+
break
|
38
|
+
end
|
39
|
+
|
40
|
+
# Ensure that this loop does not run forever if duplicates are disallowed
|
41
|
+
# In this case, we're limited to the collective size of buffered characters
|
42
|
+
|
43
|
+
break if base.length == buffer_length - 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
base.shuffle.join
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.symbols
|
54
|
+
%w[! " ' # $ % & ( ) * + , - . / : ; < = > ? ` ~ { | } @ ^]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.lowercase
|
58
|
+
%w[a b c d e f g h i j k l m n o p q r s t u v w x y z]
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.uppercase
|
62
|
+
%w[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.numbers
|
66
|
+
%w[0 1 2 3 4 5 6 7 8 9]
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: passw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Nieuwoudt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.7'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.7.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.7'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.7.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.4'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 10.4.2
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.4'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 10.4.2
|
53
|
+
description: Passw is a simple, customizable password generator for Ruby that allows
|
54
|
+
you to generate secure passwords easily
|
55
|
+
email: sean@isean.co.za
|
56
|
+
executables:
|
57
|
+
- passw
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- bin/passw
|
62
|
+
- lib/passw.rb
|
63
|
+
homepage: https://github.com/SeanNieuwoudt/passw
|
64
|
+
licenses:
|
65
|
+
- GPL-3.0
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.6.11
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Passw is a simple, customizable password generator for Ruby
|
87
|
+
test_files: []
|