require "ofwd-db" require "net/smtp" require "ofwd-local" class OfwdAccount def initialize @database = OfwdDb.new end def destroy @database.destroy end def generate_password chars = ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a newpass = Array.new(8, '').collect{chars[rand(chars.size)]}.join end def generate_verify_key chars = ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a verify_key = Array.new(32, '').collect{chars[rand(chars.size)]}.join end def verify_username(username) @database.verify_username(username) end def sanitize_username(username) username_good = false if username.length <= 32 and username.length >= 1 and username.match('\A[\w\-_.]*\Z') then username_good = true end username_good end def sanitize_email(email) email_good = false if email.length <= 32 and email.length >= 1 and email.match('\A[\w\-_.]*@[\w\-_.]*\.[\w\-_.]{2,3}\Z') then email_good = true end email_good end def check_username_availability(username) username_available = false if self.sanitize_username(username) then if not username.eql?("index.html") and not username.eql?("index.htm") and not username.eql?("index.rb") and not username.eql?("index.jsp") and not username.eql?("accounts") and not username.eql?("service") and not username.eql?("admin") then if not File.exists?("/home/ofwd/data/" + username.downcase) then if @database.check_username_availability(username) then username_available = true end end end end username_available end def sanitize_password(password) password_good = false if password.length <= 16 and password.length >= 8 and password.match('\A[\w]*\Z') then password_good = true end password_good end def approve_password(password) self.sanitize_password(password) end def change_password(username, password) @database.change_password(username, password) end def authenticate(username, password) @database.authenticate_user(username, password) end def send_password_reset_mail(recipient, password) message = <