Skip to content

Commit

Permalink
Merge pull request #40 from mayurilahane/newentries
Browse files Browse the repository at this point in the history
Added input for email,portal_url and creation date
  • Loading branch information
mayurilahane authored Jan 13, 2020
2 parents d942f56 + 4015802 commit 3fa7034
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ install:
- pip install flake8
- pip install rstcheck
script:
- flake8 --ignore=E128,W191,E117 --max-line-length 100 genpass/*.py setup.py
- flake8 --ignore=E128,W191,E117,E101 --max-line-length
100 genpass/*.py setup.py
- rstcheck README.rst


103 changes: 58 additions & 45 deletions genpass/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,69 @@
import sqlite3 # library for database


class DatabaseConnection(object):
""" Class of database entries for user's information."""
class DatabaseConnection:
""" Class of database entries for user's information."""

def __init__(self):
"""Used to create database and then to connect with generated databse file"""
self.con = sqlite3.connect('generated_password.db')
self.cursor_obj = self.con.cursor()
def __init__(self):
"""Used to create database and then to connect with generated databse file"""
self.con = sqlite3.connect("generated_password.db")
self.cursor_obj = self.con.cursor()

def create_table(self):
"""Checked for table is created? if not then created as per required values """
self.cursor_obj.execute(
"""CREATE TABLE IF NOT EXISTS passwords
(id integer PRIMARY KEY,portal_name text NOT NULL UNIQUE, password varchar)
""")
self.con.commit()
def create_table(self):
"""Checked for table is created? if not then created as per required values """
self.cursor_obj.execute(
"""CREATE TABLE IF NOT EXISTS passwords
(id integer PRIMARY KEY,portal_name text NOT NULL UNIQUE, password varchar,
creation_date varchar, email varchar, portal_url varchar)
"""
)
self.con.commit()

def insert_data(self, portal_name, password):
"""Adding values into database"""
try:
self.portal_name = portal_name
self.password = password
self.cursor_obj.execute("""INSERT INTO passwords(portal_name, password) VALUES (?, ?)""",
(self.portal_name, self.password),)
self.con.commit()
except sqlite3.IntegrityError:
print("Portal name already exists")
def insert_data(self, portal_name, password, creation_date, email, portal_url):
"""Adding values into database"""
try:
self.password = password
self.creation_date = creation_date
self.email = email
self.portal_name = portal_name
self.portal_url = portal_url
self.cursor_obj.execute(
"""INSERT INTO passwords
(portal_name, password, creation_date, email, portal_url)
VALUES (?, ?, ?, ?, ?)""",
(self.portal_name, self.password, self.creation_date, self.email, self.portal_url),
)
self.con.commit()
except sqlite3.IntegrityError:
print("Portal name already exists")

def delete_data(self, portal_name):
"""Deleting values from database"""
self.portal_name = portal_name
def delete_data(self, portal_name):
"""Deleting values from database"""
self.portal_name = portal_name

self.cursor_obj.execute("""DELETE from passwords where portal_name = ?""",
(self.portal_name,))
self.con.commit()
self.cursor_obj.execute(
"""DELETE from passwords where portal_name = ?""", (self.portal_name,)
)
self.con.commit()

def update_data(self, portal_name, password):
"""Updating values in database"""
self.portal_name = portal_name
self.password = password
self.cursor_obj.execute("""UPDATE passwords SET password =? WHERE portal_name =?""",
(self.password, self.portal_name))
self.con.commit()
def update_data(self, portal_name, password):
"""Updating values in database"""
self.portal_name = portal_name
self.password = password
self.cursor_obj.execute(
"""UPDATE passwords SET password =? WHERE portal_name =?""",
(self.password, self.portal_name),
)
self.con.commit()

def show_data(self, portal_name):
"""All inserted data will showed"""
self.portal_name = portal_name
def show_data(self, portal_name):
"""All inserted data will showed"""
self.portal_name = portal_name

self.cursor_obj.execute("""SELECT password FROM passwords WHERE portal_name=?""",
(self.portal_name,))
rows = self.cursor_obj.fetchall()
for row in rows:
return row[0]
self.con.commit()
self.cursor_obj.execute(
"""SELECT password FROM passwords WHERE portal_name=?""", (self.portal_name,)
)
rows = self.cursor_obj.fetchall()
for row in rows:
return row[0]
self.con.commit()
37 changes: 28 additions & 9 deletions genpass/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import click # Used for command line interface
import diceware # Used for creating password
from genpass.database import DatabaseConnection
from datetime import date

db_obj = DatabaseConnection()

Expand All @@ -34,38 +35,56 @@ def version():
@click.command(help="Delete password")
def delpass():
"""used to delete existing password"""
portal_name = click.prompt('Enter portal name', default="None")
portal_name = click.prompt("Enter portal name", default="None")
db_obj.delete_data(portal_name=portal_name)


@click.command(help="Update password")
def modpass():
"""Update existing password"""
portal_name = click.prompt('Enter portal name', default="None")
mod = click.prompt('Enter new password', default="None", hide_input=True)
portal_name = click.prompt("Enter portal name", default="None")
mod = click.prompt("Enter new password", default="None", hide_input=True)
db_obj.update_data(portal_name=portal_name, password=mod)


@click.command(help="Save existing passwords")
def savepass():
"""Used to take portal name and password from user"""
portal_name = click.prompt('Enter portal name', default="None")
pwd = click.prompt('Enter your password', default="None", hide_input=True)
portal_name = click.prompt("Enter portal name", default="None")
pwd = click.prompt("Enter your password", default="None", hide_input=True)
creation_date = date.today()
email = click.prompt("Enter email id", default="None")
portal_url = click.prompt("Enter portal url", default="None")
db_obj.create_table()
db_obj.insert_data(portal_name=portal_name, password=pwd)
db_obj.insert_data(
portal_name=portal_name,
password=pwd,
creation_date=creation_date,
email=email,
portal_url=portal_url,
)


@click.command(help="Create new password")
def createpass():
"""Used for taking input from user to create password"""
portal_name = click.prompt('Enter portal name', default="None")
portal_name = click.prompt("Enter portal name", default="None")
password = diceware.get_passphrase()
creation_date = date.today()
email = click.prompt("Enter email id", default="None")
portal_url = click.prompt("Enter portal url", default="None")
db_obj.create_table()
db_obj.insert_data(portal_name=portal_name, password=password)
db_obj.insert_data(
portal_name=portal_name,
password=password,
creation_date=creation_date,
email=email,
portal_url=portal_url,
)


@click.command(help="Show password")
def showpass():
portal_name = click.prompt('Enter portal name', default="None")
portal_name = click.prompt("Enter portal name", default="None")
spass = db_obj.show_data(portal_name)
print(spass)
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name="pygenpass",
packages=find_packages(),
entry_points={"console_scripts": ["pygenpass = genpass.__init__:main"]},
version="v0.1",
version="0.1",
author="Mayuri Lahane",
author_email="[email protected]",
description="Genpass - Command Line Password Manager Tool",
Expand All @@ -24,4 +24,5 @@
namespace_packages=[],
include_package_data=True,
zip_safe=False,
install_requires=install_requires,)
install_requires=install_requires,
)

0 comments on commit 3fa7034

Please sign in to comment.