Created
September 5, 2011 18:01
-
-
Save srih4ri/1195567 to your computer and use it in GitHub Desktop.
A ruby script being called by mod_authnz_external
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => "mysql", | |
:host => "localhost", | |
:username => "myuser", | |
:password => "mypass", | |
:database => "somedatabase" | |
) | |
class User < ActiveRecord::Base | |
def self.authenticate?(username, password) | |
u = find_by_username username | |
u.present? && u.hashed_password == Digest::SHA1.hexdigest(u.salt + password) | |
end | |
end | |
user = gets.chomp | |
pass = gets.chomp | |
if User.authenticate?(user,pass) | |
$stderr.puts 'Login matches pass - Accepted' | |
exit 0 | |
else | |
$stderr.puts 'Login doesnot match pass - Rejected' | |
exit 1 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
user = gets.chomp | |
pass = gets.chomp | |
puts "user: #{user}" | |
puts "pass: #{pass}" | |
ENV.each{|k,v| | |
$stderr.puts "ENV: #{k}:#{v}" | |
} | |
if (user==pass) | |
$stderr.puts 'Login matches pass - Accepted' | |
exit 0 | |
else | |
$stderr.puts 'Login doesnot match pass - Rejected' | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment