Example #1
0
    def __init__(self):
        """
		Init method.
		"""
        self.database = Database()
        self.system = System()
        self.password_manager = PasswordManager()
        self.alert = ""
Example #2
0
    def connection(self):
        """
		This method checks if the user informations is correct for the connection.
		"""
        user_email = input("\nPlease enter your email adress : ")
        user_password = input("Please enter your password : "******"{user_email} is not registered !")
        user_password_hashed = self.password_manager.hash(user_password)
        if user_informations[0][3] != user_password_hashed:
            self.system.exit_program("Wrong password !")
        self.password_manager = PasswordManager(user_informations[0][0])
        return self.password_manager.menu()
 def _get_password_manager(self, parsed_args):
     pm_home = None
     if parsed_args.pm_home:
         pm_home = parsed_args.pm_home
     elif 'PM_HOME' in os.environ:
         pm_home = os.environ['PM_HOME']
     else:
         pm_home = os.getcwd()
     return PasswordManager(pm_home)
Example #4
0
def main():

    #Ask the user for its name and check with the masterpassword on file,
    #If the name doesn't match the password offer to create a name-password combonation
    name = input("Enter your name: ")
    master = input("Enter the masterpassword for %s: " % name)

    if verifyMasterPassword(name, master):
        if sys.argv[1] == "add":
            website = input(
                "What website do you want your username and password saved for? "
            )
            username = input("Enter your username for %s: " % website)
            password = input("Enter your password for %s: " % website)

            pm = PasswordManager(name, website, username, password)
def test_oneuser(tmpdir, keyfiles):
    # ------------------------------------------------------------
    # Create a dummy gpg keyring

    gpg = get_gpg(str(tmpdir.join('gnupg')))

    assert len(list(gpg.keylist())) == 0
    assert len(list(gpg.keylist('', True))) == 0

    # Import some keys in keyring

    for keyname in ('key1.sec', 'key1.pub', 'key2.pub'):
        with keyfiles.open(keyname, 'rb') as fp:
            gpg.import_(fp)

    assert len(list(gpg.keylist())) == 2  # public
    assert len(list(gpg.keylist('', True))) == 1  # secret

    # Read fingerprints of the user's private key and other
    # available public keys.

    privkey = list(gpg.keylist('', True))[0].subkeys[0].fpr

    # ------------------------------------------------------------
    # Prepare password manager

    pm = PasswordManager(str(tmpdir.join('passwords')),
                         gpghome=str(tmpdir.join('gnupg')))

    pm.setup([privkey])

    assert list(pm.list_identities()) == [privkey]

    secret = "{'hello': 'World'}"
    pm.write_secret('hello', secret)

    assert pm.read_secret('hello') == secret
def test_oneuser(tmpdir, keyfiles):
    # ------------------------------------------------------------
    # Create a dummy gpg keyring

    gpg = get_gpg(str(tmpdir.join('gnupg')))

    assert len(list(gpg.keylist())) == 0
    assert len(list(gpg.keylist('', True))) == 0

    # Import some keys in keyring

    for keyname in ('key1.sec', 'key1.pub', 'key2.pub'):
        with keyfiles.open(keyname, 'rb') as fp:
            gpg.import_(fp)

    assert len(list(gpg.keylist())) == 2  # public
    assert len(list(gpg.keylist('', True))) == 1  # secret

    # Read fingerprints of the user's private key and other
    # available public keys.

    privkey = list(gpg.keylist('', True))[0].subkeys[0].fpr

    # ------------------------------------------------------------
    # Prepare password manager

    pm = PasswordManager(
        str(tmpdir.join('passwords')),
        gpghome=str(tmpdir.join('gnupg')))

    pm.setup([privkey])

    assert list(pm.list_identities()) == [privkey]

    secret = "{'hello': 'World'}"
    pm.write_secret('hello', secret)

    assert pm.read_secret('hello') == secret
Example #7
0
class Auth:
    def __init__(self):
        """
		Init method.
		"""
        self.database = Database()
        self.system = System()
        self.password_manager = PasswordManager()
        self.alert = ""

    def menu(self):
        """
		This method print a menu and checks the data entered by the user.
		"""
        self.system.clear_terminal()
        if self.alert != "":
            print(f"{self.alert}\n")
        print(("-" * 4) + " Connection " + ("-" * 4))
        print("1. Connect")
        print("2. Register")
        print("Q. Quit")
        print("-" * 20)
        self.choice = input(": ").lower()
        while self.choice != "q" and self.choice != "1" and self.choice != "2":
            print("Sorry, I don't understand !")
            self.choice = input(": ").lower()
        if self.choice == "1":
            self.connection()
        elif self.choice == "2":
            self.register()
        else:
            self.system.exit_program("You leave the program.")

    def connection(self):
        """
		This method checks if the user informations is correct for the connection.
		"""
        user_email = input("\nPlease enter your email adress : ")
        user_password = input("Please enter your password : "******"{user_email} is not registered !")
        user_password_hashed = self.password_manager.hash(user_password)
        if user_informations[0][3] != user_password_hashed:
            self.system.exit_program("Wrong password !")
        self.password_manager = PasswordManager(user_informations[0][0])
        return self.password_manager.menu()

    def register(self):
        """
		This method checks if the user informations is correct for the inserted in the database.
		"""
        username = input("Please enter your username : "******"Please enter your email adress : ").lower()
        user_password = input("Please enter your password : "******"{user_email} is already used !")
        self.database.adding_user_to_database(username, user_email,
                                              user_password_hashed)
        self.alert = f"{user_email} has been registered !"
        self.menu()
def test_multiple_users(tmpdir, keyfiles):
    gpg_alice = get_gpg(str(tmpdir.join('gnupg-alice')))
    gpg_bob = get_gpg(str(tmpdir.join('gnupg-bob')))
    gpg_eve = get_gpg(str(tmpdir.join('gnupg-eve')))

    passwords_dir = str(tmpdir.join('passwords'))

    for gpg in (gpg_alice, gpg_bob, gpg_eve):
        assert len(list(gpg.keylist())) == 0
        assert len(list(gpg.keylist('', True))) == 0

    # Import public keys in all keyrings..

    for gpg in (gpg_alice, gpg_bob, gpg_eve):
        for keyname in ('key1.pub', 'key2.pub', 'key3.pub'):
            with keyfiles.open(keyname, 'rb') as fp:
                gpg.import_(fp)

    # For each user's gpg home, import all public keys

    for gpg, keyfile in [
            (gpg_alice, 'key1.sec'),
            (gpg_bob, 'key2.sec'),
            (gpg_eve, 'key3.sec')]:
        with keyfiles.open(keyfile) as fp:
            gpg.import_(fp)

    # Verify operations

    for gpg in (gpg_alice, gpg_bob, gpg_eve):
        assert len(list(gpg.keylist())) == 3
        assert len(list(gpg.keylist('', True))) == 1

    # Keep key fingerprints in meaningful names..

    def _get_first_privkey_fpr(gpg):
        all_privkeys = list(gpg.keylist('', True))
        assert len(all_privkeys) == 1

        # There should be only one subkey (the master one)
        assert len(all_privkeys[0].subkeys) == 1

        return all_privkeys[0].subkeys[0].fpr

    gpg_fp_alice = _get_first_privkey_fpr(gpg_alice)
    gpg_fp_bob = _get_first_privkey_fpr(gpg_bob)
    gpg_fp_eve = _get_first_privkey_fpr(gpg_eve)

    # Make sure users have different keys!

    assert len(set((gpg_fp_alice, gpg_fp_bob, gpg_fp_eve))) == 3

    # ------------------------------------------------------------
    # Now, we can create passwor manager instances
    # and start experimenting..

    pm_alice = PasswordManager(
        passwords_dir, gpghome=str(tmpdir.join('gnupg-alice')))
    pm_bob = PasswordManager(
        passwords_dir, gpghome=str(tmpdir.join('gnupg-bob')))
    pm_eve = PasswordManager(
        passwords_dir, gpghome=str(tmpdir.join('gnupg-eve')))

    # Alice creates a new password manager.

    pm_alice.setup([gpg_fp_alice, gpg_fp_bob])
    secret = "{'username': '******', 'password': '******'}"
    pm_alice.write_secret('secret1', secret)
    assert pm_alice.read_secret('secret1') == secret

    # And Bob is able to read the secret too..
    assert pm_bob.read_secret('secret1') == secret

    # But Eve cannot. Yet
    with pytest.raises(PasswordManagerException):
        pm_eve.read_secret('secret1')

    # Alice decides to add eve..
    pm_alice.add_identity(gpg_fp_eve)

    # Now Eve can read too..
    assert pm_eve.read_secret('secret1') == secret

    # But then Alice changes her mind
    pm_alice.remove_identity(gpg_fp_eve)

    assert pm_alice.read_secret('secret1') == secret
    assert pm_bob.read_secret('secret1') == secret

    # Eve cannot read password anymore.
    with pytest.raises(PasswordManagerException):
        pm_eve.read_secret('secret1')

    # Btw, Alice things it would be better to change password too..
    secret = "{'username': '******', 'password': '******'}"
    pm_alice.write_secret('secret1', secret)

    assert pm_alice.read_secret('secret1') == secret
    assert pm_bob.read_secret('secret1') == secret
    with pytest.raises(PasswordManagerException):
        pm_eve.read_secret('secret1')
Example #9
0
from password_manager import PasswordManager
from service_structure import search_for_service, insert_service, list_service, edit_service, del_service


# Variáveis
_TITLE = 'Py Password Manager'
_AUTHOR = 'Alex'
__version__ = '0.0.1'

master_user = '******'
master_pass = '******'

# Dicionário de dados temporário.
password_manager = [
    PasswordManager(1, 'YouTube', 'alcamargos', '123456', localtime()),
    PasswordManager(2, 'DropBox', 'camargos', '7895644', localtime()),
    PasswordManager(3, 'Google', 'lopescamargos', 'camargos123456', localtime()),
    PasswordManager(4, 'Hotmail', 'sanders', '654321', localtime())
]


def show_title():
    print(f'\n{_TITLE :>40}, by {_AUTHOR}\n')


def show_continue():
    return input('\nPressione <ENTER> para continuar.')


def clear_cli():
def insert_service(service, user, password, time, db):

    return db.append(PasswordManager(len(db) + 1, service, user, password, time))
Example #11
0
from json_utils import JUtil
from games_manager import GameManager
from password_manager import PasswordManager
from referrals_manager import ReferralManager
from flask import Flask, jsonify, redirect, render_template

app = Flask(__name__)

jsonUtils = JUtil()
gamesManager = GameManager()
passwordManager = PasswordManager()
referralsManager = ReferralManager()

PASSW_PATH = "password.json"


#### Retrieve Password
@app.route('/parentpassword')
def get_pass():
    # Retrieves the current parent password
    return passwordManager.get_pass()


@app.route('/parentpassword/change/<new_pass>')
def change_pass(new_pass):
    # Changes the current password
    return passwordManager.change_pass(new_pass)


@app.route('/parentpassword/time/')
def get_time_diff():
def test_multiple_users(tmpdir, keyfiles):
    gpg_alice = get_gpg(str(tmpdir.join('gnupg-alice')))
    gpg_bob = get_gpg(str(tmpdir.join('gnupg-bob')))
    gpg_eve = get_gpg(str(tmpdir.join('gnupg-eve')))

    passwords_dir = str(tmpdir.join('passwords'))

    for gpg in (gpg_alice, gpg_bob, gpg_eve):
        assert len(list(gpg.keylist())) == 0
        assert len(list(gpg.keylist('', True))) == 0

    # Import public keys in all keyrings..

    for gpg in (gpg_alice, gpg_bob, gpg_eve):
        for keyname in ('key1.pub', 'key2.pub', 'key3.pub'):
            with keyfiles.open(keyname, 'rb') as fp:
                gpg.import_(fp)

    # For each user's gpg home, import all public keys

    for gpg, keyfile in [(gpg_alice, 'key1.sec'), (gpg_bob, 'key2.sec'),
                         (gpg_eve, 'key3.sec')]:
        with keyfiles.open(keyfile) as fp:
            gpg.import_(fp)

    # Verify operations

    for gpg in (gpg_alice, gpg_bob, gpg_eve):
        assert len(list(gpg.keylist())) == 3
        assert len(list(gpg.keylist('', True))) == 1

    # Keep key fingerprints in meaningful names..

    def _get_first_privkey_fpr(gpg):
        all_privkeys = list(gpg.keylist('', True))
        assert len(all_privkeys) == 1

        # There should be only one subkey (the master one)
        assert len(all_privkeys[0].subkeys) == 1

        return all_privkeys[0].subkeys[0].fpr

    gpg_fp_alice = _get_first_privkey_fpr(gpg_alice)
    gpg_fp_bob = _get_first_privkey_fpr(gpg_bob)
    gpg_fp_eve = _get_first_privkey_fpr(gpg_eve)

    # Make sure users have different keys!

    assert len(set((gpg_fp_alice, gpg_fp_bob, gpg_fp_eve))) == 3

    # ------------------------------------------------------------
    # Now, we can create passwor manager instances
    # and start experimenting..

    pm_alice = PasswordManager(passwords_dir,
                               gpghome=str(tmpdir.join('gnupg-alice')))
    pm_bob = PasswordManager(passwords_dir,
                             gpghome=str(tmpdir.join('gnupg-bob')))
    pm_eve = PasswordManager(passwords_dir,
                             gpghome=str(tmpdir.join('gnupg-eve')))

    # Alice creates a new password manager.

    pm_alice.setup([gpg_fp_alice, gpg_fp_bob])
    secret = "{'username': '******', 'password': '******'}"
    pm_alice.write_secret('secret1', secret)
    assert pm_alice.read_secret('secret1') == secret

    # And Bob is able to read the secret too..
    assert pm_bob.read_secret('secret1') == secret

    # But Eve cannot. Yet
    with pytest.raises(PasswordManagerException):
        pm_eve.read_secret('secret1')

    # Alice decides to add eve..
    pm_alice.add_identity(gpg_fp_eve)

    # Now Eve can read too..
    assert pm_eve.read_secret('secret1') == secret

    # But then Alice changes her mind
    pm_alice.remove_identity(gpg_fp_eve)

    assert pm_alice.read_secret('secret1') == secret
    assert pm_bob.read_secret('secret1') == secret

    # Eve cannot read password anymore.
    with pytest.raises(PasswordManagerException):
        pm_eve.read_secret('secret1')

    # Btw, Alice things it would be better to change password too..
    secret = "{'username': '******', 'password': '******'}"
    pm_alice.write_secret('secret1', secret)

    assert pm_alice.read_secret('secret1') == secret
    assert pm_bob.read_secret('secret1') == secret
    with pytest.raises(PasswordManagerException):
        pm_eve.read_secret('secret1')
Example #13
0
from password_manager import PasswordManager

if __name__ == '__main__':
    password_manager = PasswordManager()
    password_manager.execute()
Example #14
0
def main():
    PasswordManager()
Example #15
0
from password_manager import PasswordManager

import re

def error(s):
  print('=== ERROR: %s' % s)

print('Initializing password maanger')
password_manager = PasswordManager('123456')

print('Adding passwords to password manager')
kvs = { 'domain1': 'password1', 
        'domain2': 'password2',
        'domain3': 'password3' }
for domain in kvs:
  password_manager.set(domain, kvs[domain])

print('Trying to fetch passwords from password manager')
for domain in kvs:
  pw = password_manager.get(domain)
  if pw != kvs[domain]:
    error('get failed for domain %s (expected %s, received %s)' % (domain, kvs[domain], pw))
pw = password_manager.get('non-existent')
if pw is not None:
  error('get failed for domain non-existent (expected None, received %s)' % pw)

print('Trying to remove passwords from password manager')
if not password_manager.remove('domain1'):
  error('remove failed for domain domain1')
pw = password_manager.get('domain1')
if pw is not None: