Wednesday, June 22, 2011

Ruby code for POP3 auth

Simple Ruby code for pop3 auth (Use at your own risk)


def Connect(server,port,username,password)
puts " try ... #{server}:#{port} - #{username}:#{password}"
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) # enable SSL default port 995
auth = Net::POP3.start(server, port, username, password)

rescue SocketError, Timeout::Error, OpenSSL::SSL::SSLError,EOFError
puts "Connect Error: #{$!}"

rescue Errno::ECONNREFUSED, Errno::ECONNRESET
puts "Connect Error: #{$!}"
sleep 0.60

rescue Net::POPAuthenticationError
puts "Connect Error: #{$!}"
else
auth.finish
return username,password
end

Tuesday, June 14, 2011

Simple Ruby Credit Card Validator

This code below is a ruby implementation of Luhn Algorithm to validate credit cards numbers.


#!/usr/bin/env ruby

def is_valid(number)
x = number.split("")

i = 0

a = Array.new()

while (i < x.size) do
a.push(x[i].to_i*2)
i = i + 1
a.push(x[i].to_i)
i = i + 1
end
if (a.join("").split("").inject(0){|sum,item| sum + item.to_i} % 10 == 0)
return true
else
return false
end
end

puts is_valid(ARGV[0])