Adds Redmine::Utils.random_hex for generating a random hex string.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9071 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-03-04 11:05:02 +00:00
parent 8db9ffbd8b
commit af75583b23
5 changed files with 12 additions and 5 deletions

View File

@ -69,7 +69,7 @@ class AttachmentsController < ApplicationController
@attachment = Attachment.new(:file => request.body)
@attachment.author = User.current
@attachment.filename = ActiveSupport::SecureRandom.hex(16)
@attachment.filename = Redmine::Utils.random_hex(16)
if @attachment.save
respond_to do |format|

View File

@ -367,11 +367,11 @@ class MailHandler < ActionMailer::Base
user.lastname = '-' if user.lastname.blank?
password_length = [Setting.password_min_length.to_i, 10].max
user.password = ActiveSupport::SecureRandom.hex(password_length / 2 + 1)
user.password = Redmine::Utils.random_hex(password_length / 2 + 1)
user.language = Setting.default_language
unless user.valid?
user.login = "user#{ActiveSupport::SecureRandom.hex(6)}" unless user.errors[:login].blank?
user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank?
user.firstname = "-" unless user.errors[:firstname].blank?
user.lastname = "-" unless user.errors[:lastname].blank?
end

View File

@ -39,7 +39,7 @@ class Token < ActiveRecord::Base
private
def self.generate_token_value
ActiveSupport::SecureRandom.hex(20)
Redmine::Utils.random_hex(20)
end
# Removes obsolete tokens (same user and action)

View File

@ -610,7 +610,7 @@ class User < Principal
# Returns a 128bits random salt as a hex string (32 chars long)
def self.generate_salt
ActiveSupport::SecureRandom.hex(16)
Redmine::Utils.random_hex(16)
end
end

View File

@ -33,6 +33,13 @@ module Redmine
ActionController::AbstractRequest.relative_url_root=arg
end
end
# Generates a n bytes random hex string
# Example:
# random_hex(4) # => "89b8c729"
def random_hex(n)
ActiveSupport::SecureRandom.hex(n)
end
end
end
end