Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
sample_app/config/initializers/secret_token.rb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (23 sloc)
1.02 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Be sure to restart your server when you modify this file. | |
# Your secret key is used for verifying the integrity of signed cookies. | |
# If you change this key, all old signed cookies will become invalid! | |
# Make sure the secret is at least 30 characters and all random, | |
# no regular words or you'll be exposed to dictionary attacks. | |
# You can use `rake secret` to generate a secure secret key. | |
# Make sure your secret_key_base is kept private | |
# if you're sharing your code publicly. | |
#SampleApp::Application.config.secret_key_base = 'f417003a8ee632b2b73a04bef16d96132209436396f0a7744ff8782e79f7d4753f3c36d95ddf67c0fb5cac0fad317c6f01ba30d71bd0ae8583fdb06602fae876' | |
require 'securerandom' | |
def secure_token | |
token_file = Rails.root.join('.secret') | |
if File.exist?(token_file) | |
# Use the existing token. | |
File.read(token_file).chomp | |
else | |
# Generate a new token and store it in token_file. | |
token = SecureRandom.hex(64) | |
File.write(token_file, token) | |
token | |
end | |
end | |
SampleApp::Application.config.secret_key_base = secure_token |