Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
SixArm.com » Ruby » SecureToken class to generate a strong text string
CSS JavaScript HTML Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.yardoc
coverage
doc
lib
test
.codeclimate.yml
.document
.gemtest
.gitignore
.rspec
.travis.yml
CHANGES.md
CONTRIBUTING.md
Gemfile
Gemfile.lock
LICENSE.md
README.md
Rakefile
VERSION
sixarm_ruby_secure_token-2.1.0-sha512.txt
sixarm_ruby_secure_token-2.1.0.gem
sixarm_ruby_secure_token-2.1.1.gem
sixarm_ruby_secure_token.gemspec

README.md

Ruby »
SecureToken to generate a random string

Code Climate Build Status

Introduction

This is a secure token generator that creates cryptographically-strong strings.

Example:

SecureToken.new  
#=> "kavzwbnxremyqckwtxrumxzapmfmpwve"

For docs go to http://sixarm.com/sixarm_ruby_secure_token/doc

Want to help? We're happy to get pull requests.

Install

To install using a Gemfile, add this:

gem "sixarm_ruby_secure_token", ">= 2.1.1", "< 3"

To install using the command line, run this:

gem install sixarm_ruby_secure_token -v ">= 2.1.1, < 3"

To install using the command line with high security, run this:

wget http://sixarm.com/sixarm.pem
gem cert --add sixarm.pem && gem sources --add http://sixarm.com
gem install sixarm_ruby_secure_token -v ">= 2.1.1, < 3" --trust-policy HighSecurity

To require the gem in your code:

require "sixarm_ruby_secure_token"

Details

This generates a 32-character token of lowercase letters.

This uses Ruby's SecureRandom methods for strong security.

SecureToken is a string, so you can do any string methods on it.

You can change how tokens are randomly created by using cusomtization.

Customization

To customize the choices:

SecureToken.choices = ['a','b','c']
SecureToken.new 
#=> "acbbaccbabcabcabbcabcabcdbbcabcb"

To customize the length:

SecureToken.length = 8
SecureToken.new 
#=> "kavzwbnx"

The default length is 32.

The default choices are the lowercase English letters 'a' to 'z', but omitting the letters 'i', 'l', 'o', 'q'. We omit these because our user testing shows these characters are often misunderstood by users.

Enumeration

To use an enumeration #next method:

s = SecureToken.new
s.next  #=> 'bacbaacb'
Something went wrong with that request. Please try again.