secure_random_string 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/secure_random_string.rb +28 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a602c21fca2834aa395a9e0d0495e1fd85058084
|
4
|
+
data.tar.gz: 0a269b86abc7a9117d109ec6581fc12b45193357
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e23eb87bfe5c0c6f5b69486ea3c732d8e90bc1507497d0516a83053005d87875424741ab241159144f83c3b563aa31f11d1bb7723ad1bb8e1e48535261a2b488
|
7
|
+
data.tar.gz: 60b6dff0ded7bce30de77ea85968de244dc7260a5c1ed86f72b7dc834dcc1fcf838eb8a2a49fad955f80815b90094378f8ce264b17e03e53b7c3f825bd29bccf
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
class SecureRandomString < String
|
4
|
+
|
5
|
+
UC_LETTERS = ('A'..'Z').to_a.freeze
|
6
|
+
LC_LETTERS = ('a'..'z').to_a.freeze
|
7
|
+
NUMBERS = (0..9).to_a.freeze
|
8
|
+
CHARACTERS = %w{/ . , + ^ [ ] - + - = _ * % @ : # ~}.freeze
|
9
|
+
|
10
|
+
def initialize(length, options = {})
|
11
|
+
# By default, don't include characters in strings.
|
12
|
+
options[:characters] ||= false
|
13
|
+
|
14
|
+
# Build a set of possible characters for the string
|
15
|
+
set = []
|
16
|
+
set += UC_LETTERS unless options[:uppercase] == false
|
17
|
+
set += LC_LETTERS unless options[:lowercase] == false
|
18
|
+
set += NUMBERS unless options[:numbers] == false
|
19
|
+
set += CHARACTERS unless options[:characters] == false
|
20
|
+
set += options[:extra] if options[:extra].is_a?(Array)
|
21
|
+
|
22
|
+
# Populate the string
|
23
|
+
length.times.each do
|
24
|
+
self << set[SecureRandom.random_number(set.size)].to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secure_random_string
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A library for generating random string
|
14
|
+
email:
|
15
|
+
- me@adamcooke.io
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/secure_random_string.rb
|
21
|
+
homepage: https://github.com/adamcooke/secure_random_string
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A library for generating random string
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|