password_genie 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/password_genie.rb +79 -20
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffac553f7f831402019caa9247f7c41d42c8fe94
4
- data.tar.gz: 31f5881099c8ef55d1304216407ed476673f365a
3
+ metadata.gz: 410cb42e5da2ca1c2477fa5d5da8c55ca360ecca
4
+ data.tar.gz: 116a44efaaadb730961aaf74455c12b815db1b05
5
5
  SHA512:
6
- metadata.gz: 2dd3e0802621da04431927662d97fd835161228d54a605e42a1102fedaf5a33c1625cada326bcf90510c6a9c336034d6048ef47a2e6aac918fabf5b694863647
7
- data.tar.gz: e31dd89b143e58e72b1dc2a98a7ac387ba85cc317b4f158d1bdf229b891b2423db18a49e89cb7069e0b3d1dd455a417fd636c56fe2c91a96d4402e0a37bf583a
6
+ metadata.gz: 7de69552b0b12f7a4ba966fcf0f7a27e0546485732217a46bacf60c3ce8324deabd8cc1ae916af2a0cd82b54e0e93b69cc411cedd9270910834b295aae9a1253
7
+ data.tar.gz: 3167f2fc90b401b42b1e606f6c83ff86a9d620eb9112052d99b0ec181d8bd6215e8d7b8338ed70d002fd415cd7c9ced119e75522763d517f6ec4bf1bdaff5d45
@@ -1,10 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  #password_genie.rb
3
3
 
4
+ require 'sqlite3'
5
+
4
6
  class WordBank
5
7
  attr_reader :word_bank, :number, :special_chars
6
8
 
7
9
  def word_bank=(words)
10
+ if words == ""
11
+ raise "can't be empty."
12
+ end
8
13
  word_bank= words.split("").to_a
9
14
  word_bank.delete(" ")
10
15
  unless word_bank.is_a?(Array)
@@ -30,7 +35,7 @@ class WordBank
30
35
  def initialize(words,number=8)
31
36
  self.word_bank = words
32
37
  self.number = number
33
- self.special_chars = special_chars
38
+ self.special_chars = special_chars.to_a
34
39
  @password_ary = []
35
40
  @numbers= (0..9).to_a
36
41
  end
@@ -46,13 +51,17 @@ class WordBank
46
51
  end
47
52
 
48
53
  def create
54
+ puts "wordbank: #{@word_bank}, special #{@special_chars}"
49
55
  i = number
50
- while i != 0
51
- if i == 2 && word_bank.include?(@special_chars) && @password_ary.include?(@special_chars) == false
56
+ puts "create"
57
+ until i == 0
58
+ puts " i is #{i}"
59
+ if i == 2 && (@password_ary.include?(@special_chars) == false && @word_bank.include?(@special_chars))
52
60
  @password_ary << @special_chars[rand(0..@special_chars.size)]
53
61
  puts "1 == 2"
54
- elsif i == 1 && word_bank.include?(@numbers) && @password_ary.include?(@numbers) == false
55
- @password_ary << @numbers[rand(1..@numbers.size)]
62
+ end
63
+ if i == 1 && (@password_ary.include?(@numbers) == false && @word_bank.include?(@numbers))
64
+ @password_ary << @numbers[rand(0..@numbers.size)]
56
65
  puts "i == 1"
57
66
  end
58
67
  letter = rand(0..word_bank.size)
@@ -65,25 +74,64 @@ class WordBank
65
74
  @password
66
75
  end
67
76
 
68
- def save_info(site,username)
69
- myfile=File.open('site_info.txt','a+') do |f|
70
- puts "[#{site}] username: #{username} | password: #{@password}"
71
- f.puts("[#{site}] username: #{username} | password: #{@password}")
77
+ def save_info(site,username,password=@password)
78
+ begin
79
+ db = SQLite3::Database.open('genie.db')
80
+ puts db.get_first_value "select SQLite_VERSION()"
81
+ db.results_as_hash = true
82
+ site_in = site; username_in = username; pw_in = password
83
+ db.transaction
84
+ db.execute "create table if not exists site_info(Id INTEGER PRIMARY KEY, Site TEXT, Username TEXT, Password TEXT)"
85
+ db_in = db.prepare "insert into site_info(Site, Username, Password) values(:site_in, :username_in, :pw_in)"
86
+ db_in.execute site_in, username_in, pw_in
87
+ db.commit
88
+ rescue SQLite3::Exception => e
89
+ puts "something went wrong: #{e}"
90
+ db.rollback
91
+ ensure
92
+ db_in.close if db_in
93
+ db.close if db
72
94
  end
73
95
  end
74
96
 
75
97
  def find_info(info)
76
- return "please create a password directory first" unless File.exist?('site_info.txt')
77
- IO.foreach('site_info.txt') do |line|
78
- return line if line.include?(info)
79
- end
80
- return "no match"
98
+ begin
99
+ db = SQLite3::Database.open('genie.db')
100
+ puts db.get_first_value "select SQLite_VERSION()"
101
+ return "please create a directory first" unless File.exist?('genie.db')
102
+ puts "hello, again."
103
+ puts info
104
+ print_out = db.execute2 "SELECT * FROM site_info WHERE Site= :info_in OR Username = :info", info
105
+ puts "foo"
106
+ return "no match" unless print_out != nil
107
+ puts "bar"
108
+ print_out.each do |line|
109
+ puts "[%5s] %8s | %s" % [line[1], line[2], line[3]]
110
+ end
111
+ puts "boo"
112
+ rescue SQLite3::Exception => e
113
+ puts "foo2"
114
+ puts e
115
+ ensure
116
+ db.close if db
117
+ end
81
118
  end
82
119
 
83
- def push_info(site,username,password)
84
- my_file = File.open('site_info.txt', 'a+') do |f|
85
- f.puts("[#{site}] username: #{username} | password: #{password}")
86
- end
120
+ def add_or_replace_info(site, username, password)
121
+ begin
122
+ db = SQLite3::Database.open('genie.db')
123
+ return "please set up database by restarting and choosing [1]" unless File.file?('genie.db')
124
+ puts db.get_first_value "select SQLite_VERSION()"
125
+ db.transaction
126
+ db.execute2 "UPDATE site_info SET Password = :password WHERE Site = :site AND Username = :username", password, site, username
127
+ db.commit
128
+ puts "you made #{db.changes} changes."
129
+ rescue SQLite3::Exception => e
130
+ puts e
131
+ db.rollback
132
+ ensure
133
+ db.close if db
134
+ end
87
135
  end
88
136
  end
89
137
 
@@ -91,7 +139,7 @@ go = true
91
139
 
92
140
  while go
93
141
  puts "enter [1] to CREATE a new password\nenter [2] to LOOKUP a password"
94
- puts "enter [3] to ADD an already existing password\nenter [4] to EXIT"
142
+ puts "enter [3] to ADD/CHANGE an already existing password\nenter [4] to EXIT"
95
143
 
96
144
  choice = gets.chomp.to_i
97
145
 
@@ -100,6 +148,12 @@ while go
100
148
  puts "How long do you want your password to be?"
101
149
 
102
150
  number = gets.chomp.to_i
151
+
152
+ unless number.is_a?(Integer)
153
+ puts "number MUST be an integer."
154
+ next
155
+ end
156
+
103
157
  if number == 1
104
158
  word_number = "character"
105
159
  else
@@ -144,14 +198,19 @@ while go
144
198
  puts x.find_info(word)
145
199
  next
146
200
  elsif choice == 3
201
+ puts "**MUST supply an EXISTING site and username**"
147
202
  print "enter site: "
148
203
  site = gets.chomp
149
204
  print "enter username: "
150
205
  username = gets.chomp
206
+ if site == '' || username == ''
207
+ puts "BOTH site and username must be filled in. Back to the beginning."
208
+ next
209
+ end
151
210
  print "enter password: "
152
211
  password = gets.chomp
153
212
  x = WordBank.new(site)
154
- x.push_info(site,username,password)
213
+ x.add_or_replace_info(site,username,password)
155
214
  next
156
215
  elsif choice == 4
157
216
  go = false
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: password_genie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - fookh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-01 00:00:00.000000000 Z
11
+ date: 2019-02-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: a simple tool to build a password based on user defined parameters 2.
14
- archive passwords, usernames, and corresponding site data 3. search data and 4.
15
- push an existing password into txt file
13
+ description: a simple tool to build a password repository based on user defined parameters
14
+ 2. archive passwords, usernames, and corresponding site data 3. search data and
15
+ 4. push an existing password into sqlite
16
16
  email: foo@yetispeak.com
17
17
  executables: []
18
18
  extensions: []
@@ -42,5 +42,5 @@ rubyforge_project:
42
42
  rubygems_version: 2.5.2.1
43
43
  signing_key:
44
44
  specification_version: 4
45
- summary: introduces a puts function for CURRENT passwords
45
+ summary: migrated over to sqlite
46
46
  test_files: []