Changeset 226
- Timestamp:
- 09/26/2007 14:14:55 (14 months ago)
- Files:
-
- 1 modified
-
trunk/lib/camping/session.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/camping/session.rb
r225 r226 19 19 class Session < Base 20 20 serialize :ivars 21 # SQL injection to bypass id field checks 22 set_primary_key '"="" OR "' 21 set_primary_key :hashid 23 22 24 23 def []=(k, v) # :nodoc: … … 29 28 end 30 29 30 protected 31 31 RAND_CHARS = [*'A'..'Z'] + [*'0'..'9'] + [*'a'..'z'] 32 def before_create 33 rand_max = RAND_CHARS.size 34 sid = (0...32).inject("") { |ret,_| ret << RAND_CHARS[rand(rand_max)] } 35 write_attribute('hashid', sid) 36 end 32 37 33 38 # Generates a new session ID and creates a row for the new session in the database. 34 39 def self.generate cookies 35 rand_max = RAND_CHARS.size 36 sid = (0...32).inject("") { |ret,_| ret << RAND_CHARS[rand(rand_max)] } 37 sess = Session.create :hashid => sid, :ivars => Camping::H[] 40 sess = Session.create :ivars => Camping::H[] 38 41 cookies.camping_sid = sess.hashid 39 42 sess
