-
Notifications
You must be signed in to change notification settings - Fork 2
/
thm-authentication.rb
64 lines (53 loc) · 1.59 KB
/
thm-authentication.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
########################################################################
#
# Author: Brian Hood
#
# Email: <brianh6854@googlemail.com>
# Description: Threatmonitor User Administration
#
# Extends the functionality of the Thm module adding Authorization
# Adding Authentication to the Privileges model
#
########################################################################
require "#{File.dirname(__FILE__)}/lib/thm.rb"
require "#{File.dirname(__FILE__)}/thm-privileges.rb"
conf = Thm::FileServices.new
conf.thmhome?
module Thm::Authorization
class Authentication < Thm::DataServices
attr_reader :thmsession
attr_accessor :thmsesslock
def initialize
super
@debug = true
end
def login(username, password)
obj = Thm::Authorization::Privileges.new
pwhash = obj.mkhash(password)
sqlusrcnt = "SELECT count(*) as num FROM users WHERE username = '#{username}' AND password = '#{pwhash}'"
resusrcnt = @conn.query("#{sqlusrcnt}")
rowusrcnt = resusrcnt.fetch_hash
puts "#{rowusrcnt["num"].to_i}"
if rowusrcnt["num"].to_i == 1
puts "Authentication Success"
@thmsession = Tools::guid.to_s
@thmsesslock = "OK"
else
@thmsession = "failure"
@thmsesslock = "FAILURE"
puts "\e[1;31m\Failure to Authenticate \e[0m\ "
end
end
def login_session?
if @thmsession != "failure" or @thmsession != nil
return true
else
return false
end
end
def logout
@thmsession = nil
@thmsesslock = "DEADBEEF"
end
end
end