summaryrefslogtreecommitdiff
path: root/lib/trocla/util.rb
blob: 3461bb2491f6aa79221da170be5aa0c124e8ba6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Trocla
  class Util
    class << self
      def random_str(length=12)
        (1..length).collect{|a| chars[rand(chars.size)] }.join.to_s
      end

      def salt(length=8)
        (1..length).collect{|a| normal_chars[rand(normal_chars.size)] }.join.to_s
      end

      private
      def chars
        @chars ||= normal_chars + special_chars
      end
      def normal_chars
        @normal_chars ||= ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
      end
      def special_chars
        @special_chars ||= "+*%/()@&=?![]{}-_.,;:".split(//)
      end
    end
  end
end