# Class: User

User Class

# Public Class Methods

### authorize (username, cleartxtpw)

Authorize a user by name. Passes in cleartxt version of password

Show source...

         # File bbs/lib/dbmodels/user.rb, line 170
    170:   def self.authorize(username, cleartxtpw)
    171:     user = self[:login=>username]
    172:     unless user.nil?
    173:       # Reject user if Group level is 255 or higher, or account is set to locked
    174:       unless user.islocked == true || Group.find(:id => user.group_id).level <= 1
    175:         dbpw = BCrypt::Password.new("#{user.password}")
    176:         if dbpw == "#{cleartxtpw}"
    177:           return {:result=>"true"}
    178:         else
    179:           user.set(:login_failures => user.login_failures+1)
    180:           if user.login_failures >= $cfg['login']['lockout']
    181:             user.set(:islocked => true)
    182:           end
    183:           user.save
    184:           return {:result => "false", :failures => user.login_failures, :islocked=> user.islocked}
    185:         end
    186:       else
    187:         return {:result => "locked"}
    188:       end
    189:     else
    190:         return {:result=>"invalid"}
    191:     end #/unless
    192:   end

### clearfailed (username)

Clear login_failures count on a user

Show source...

         # File bbs/lib/dbmodels/user.rb, line 195
    195:   def self.clearfailed(username)
    196:     user = self[:login=>username]
    197:     user.set(:islocked=>false, :login_failures=>0)
    198:     user.save
    199:   end

### countlogin (username)

Count the login by incrementing the DB login_count and timestamp of login_last

Show source...

         # File bbs/lib/dbmodels/user.rb, line 202
    202:   def self.countlogin(username)
    203:     user = self[:login=>username]
    204:     user.set(:login_total=>user.login_total+1, :login_last => Time.now)
    205:     user.save
    206:   end

### cryptpassword (cleartxt)

Encrypt Password with BCrypt

Show source...

        # File bbs/lib/dbmodels/user.rb, line 75
    75:   def self.cryptpassword(cleartxt)
    76:     password = BCrypt::Password.create(cleartxt)
    77:     return password
    78:   end

### exists? (username)

Quick validation for login or other routines to see if a specified user exists

Show source...

         # File bbs/lib/dbmodels/user.rb, line 160
    160:   def self.exists?(username)
    161:     user = self[:login=>username]
    162:     if user.nil?
    163:       return false
    164:     else
    165:       return true
    166:     end
    167:   end

### validatepw (pw1, pw2)

Simple validator to compare 2 passwords in any presented format

Show source...

         # File bbs/lib/dbmodels/user.rb, line 209
    209:   def self.validatepw(pw1, pw2)
    210:     if pw1 == pw2
    211:       return true
    212:     else
    213:       return false
    214:     end
    215:   end