diff options
-rw-r--r-- | app/controllers/attachments_controller.rb | 2 | ||||
-rw-r--r-- | app/models/mail_handler.rb | 4 | ||||
-rw-r--r-- | app/models/token.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | lib/redmine/utils.rb | 7 |
5 files changed, 12 insertions, 5 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 9d77993ab..37b256a94 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -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| diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 9c9665183..2d50a8057 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -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 diff --git a/app/models/token.rb b/app/models/token.rb index 89d1352ee..c6425f0fa 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index 15cdce1b2..a37c4dffa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/lib/redmine/utils.rb b/lib/redmine/utils.rb index 593406eb1..96580168f 100644 --- a/lib/redmine/utils.rb +++ b/lib/redmine/utils.rb @@ -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 |