Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Separated some calls out into new library. General code clean up.

  • Loading branch information...
commit a4db9ac6091f5b386f75cfde6a782f416dc46edd 1 parent 94384cc
Mike Skalnik authored September 24, 2008
9  History.txt
... ...
@@ -1,3 +1,12 @@
  1
+=== 0.0.4 / 2008-09-24
  2
+ * Separated some calls into new library.
  3
+
  4
+=== 0.0.3 / 2008-09-24
  5
+ * Initial working copy. A bit rough though.
  6
+
  7
+=== 0.0.2 / 2008-09-23
  8
+ * Almost working copy.
  9
+
1 10
 === 0.0.1 / 2008-09-22
2 11
 
3 12
  * Initial creation.
3  Manifest.txt
@@ -2,4 +2,5 @@ History.txt
2 2
 Manifest.txt
3 3
 README.txt
4 4
 Rakefile
5  
-bin/lawn
  5
+bin/lawn
  6
+lib/lawn.rb
3  Rakefile
... ...
@@ -1,7 +1,8 @@
1 1
 require 'rubygems'
2 2
 require 'hoe'
  3
+require 'lib/lawn.rb'
3 4
 
4  
-Hoe.new('lawn-login', "0.0.3") do |p|
  5
+Hoe.new('lawn-login', Lawn::VERSION) do |p|
5 6
   p.developer('Mike Skalnik', 'mike.skalnik@gmail.com')
6 7
   p.remote_rdoc_dir = '' # Release to root
7 8
   p.description = "A small gem which provides a secure method of logging into the GATech LAWN network."
29  bin/lawn
@@ -3,49 +3,44 @@ require 'rubygems'
3 3
 require 'crypt/blowfish'
4 4
 require 'optparse'
5 5
 require 'yaml'
  6
+require '../lib/lawn'
6 7
 
7 8
 options = Hash.new(false)
8 9
 
9 10
 OptionParser.new do |opts|
10 11
   opts.banner = "Usage: lawn [options]"
11 12
   opts.on("-s", "--setup", "Re-run the interactive setup. For example, when LAWN password is changed.") do |opt|
12  
-    options['setup'] = true
  13
+    options[:setup] = true
13 14
   end
14 15
   opts.on("-p", "--password", "Reset your LAWN password.") do |opt|
15  
-    options['password'] = true
  16
+    options[:password] = true
16 17
   end
17 18
 end.parse!
18 19
 
19 20
 file = File.expand_path('~/.lawn')
20 21
 info = Hash.new
21 22
 
22  
-if !File.exists?(file) or options['setup'] # First run or rerun setup.  
  23
+if !File.exists?(file) or options[:setup] # First run or rerun setup.  
23 24
   print "LAWN username? "
24 25
   info[:username] = gets.chomp
25 26
   print "LAWN password? "
26  
-  unencrypted_password = gets.chomp
27  
-  
28  
-  blowfish = Crypt::Blowfish.new(info[:username])
29  
-    
30  
-  info[:encrypted_password] = blowfish.encrypt_block(unencrypted_password)
31  
-  unencrypted_password = nil
32  
-  
33  
-  if info[:username].length < 7
34  
-    info[:encryption_password] = info[:username] << ("!" * 7)
35  
-  else
36  
-    info[:encryption_password] = info[:username]
37  
-  end
  27
+  info[:encrypted_password] = Lawn.encrypt_password(Lawn.get_encryption_password(info[:username]), gets.chomp)
38 28
   
39 29
   File.open(file, 'w') { |f|
40 30
     f.write(YAML::dump(info))
41 31
   }
42  
-  puts "OK. Lawn-login is now setup. To login next time, run `lawn <encryption_password>`"
  32
+  puts "OK. Lawn-login is now setup. To login next time, run `lawn`"
43 33
   exit
44 34
 else # File exists, so lets get the info from there!
45 35
   info = YAML.load_file(file)
46 36
 end
47 37
 
48  
-blowfish = Crypt::Blowfish.new(info[:encryption_password])
  38
+if options[:password]
  39
+  print "New LAWN password? "
  40
+  info[:encrypted_password] = Lawn.encrypt_password(Lawn.get_encryption_password(info[:username]), gets.chomp)
  41
+end
  42
+
  43
+blowfish = Crypt::Blowfish.new(Lawn.get_encryption_password(info[:username]))
49 44
 PASSWORD = blowfish.decrypt_block(info[:encrypted_password])
50 45
 USERNAME = info[:username]
51 46
 
2  lawn-login.gemspec
... ...
@@ -1,6 +1,6 @@
1 1
 Gem::Specification.new do |s|
2 2
   s.name = %q{lawn-login}
3  
-  s.version = "0.0.3"
  3
+  s.version = "0.0.4"
4 4
 
5 5
   s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6 6
   s.authors = ["Mike Skalnik"]
18  lib/lawn.rb
... ...
@@ -0,0 +1,18 @@
  1
+require 'crypt/blowfish'
  2
+module Lawn
  3
+  extend self
  4
+  VERSION = "0.0.4"
  5
+  
  6
+  def get_encryption_password(username)
  7
+    if username.length < 7
  8
+      username << ("!" * 7)
  9
+    else
  10
+      username
  11
+    end
  12
+  end
  13
+  
  14
+  def encrypt_password(encryption_password, password)
  15
+    blowfish = Crypt::Blowfish.new(encryption_password)
  16
+    blowfish.encrypt_block(password)
  17
+  end
  18
+end

0 notes on commit a4db9ac

Please sign in to comment.
Something went wrong with that request. Please try again.