def __init__(self, parent=None, mainwindow=None): super(Sign, self).__init__(parent) self.setupUi(self) self.main = mainwindow self.register = Register(self) self.passwd = Password(self) self.set_connect()
def test_delete_passwords(self): self.new_password.save_password() test_password = Password("facebook","Zubeir","Abubakar","Black-heart","5250") test_password.save_password() self.new_password.delete_passwords() self.assertEqual(len(Password.password_list),1)
def test_delete_password(self): # check if we can remove password from our list self.password.save_password() test_password = Password("Test", "user", "*****@*****.**", "110p05124h") test_password.save_password() self.new_password.delete_password() # deleting password self.assertEqual(len(Password.password_list), 1)
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_password = Password( 'Evans', 'Opindi', '0740772578', '*****@*****.**', 'evracheche1999') # create passwordnew_password object
def setUp(self): ''' set up method to run before each test case ''' self.new_password = Password("instagram", "James", "Muriuki", "cmaina", "3094")
def test_delete_passwords(self): self.new_password.save_password() test_password = Password("instagram", "charles", "maina", "charles34", "1234") test_password.save_password() self.new_password.delete_passwords() self.assertEqual(len(Password.password_list), 1)
def testBoth(self): f, filename = tempfile.mkstemp() self.addCleanup(os.unlink, filename) Password.KEYFILE = filename pwd = "Test password" encrypted = Password.encrypt(pwd) self.assertEqual(pwd, Password.decrypt(encrypted)) self.assertEqual(os)
def test_delete_password(self): self.new_password.save_Password() test_password = Password("flo", "boel", "flock", "7350") test_password.save_Password() self.new_password.delete_password() self.assertEqual(len(Password.password_list), 1)
def test_password_exists(self): # checking if we return the booleon if the passoword is not found self.new_password.Password() test_password = Password("Test", "user", "*****@*****.**", "110p05124h") test_password.save_password() password_exists = Password.password_exists("110p05124") self.assertTrue(password_exists)
def test_find_by_email(self): # checking if the password is in the list and the display the info self.new_password.save_password() test_password = Password("Test", "user", "wycliffkerongogmail.com", "110p05124h") test_password.save_password() found_password = Password.find_by_email("31740141") self.assertEqual(found_password.email, password.email)
def test_password_exist(self): self.new_account.save_password() test_password = Password("Test", "user", "0711223344", "*****@*****.**") # new password test_password.save_password() password_exists = Password.password_exist("0711223344") self.assertTrue(password_exists)
def test_delete_password(self): self.new_account.save_password() test_password = Password("Test", "user", "0712345678", "*****@*****.**") # new password test_password.save_password() self.new_account.delete_password() # deleting a password objeect self.assertEqual(len(Password.password_list), 1)
def test_save_multiple_password(self): ''' test_save_multiple_password to check if we can save multiple password objects to our password_list ''' self.new_password.save_password() test_password = Password("Micah", "Mutugi", "python") # new password test_password.save_password() self.assertEqual(len(Password.password_list), 2)
def test_save_multiple_password(self): ''' test_save_multiple_password to check if we can save multiple password objects to our password_list ''' self.new_password.save_password() test_password = Password("Test","user","0746432419","*****@*****.**") # new password test_password.save_password() self.assertEqual(len(Password.password_list),2)
def test_find_password_by_number(self): self.new_account.save_password() test_password = Password("Test", "user", "0711223344", "*****@*****.**") # new password test_password.save_password() found_password = Password.find_by_number("0711223344") self.assertEqual(found_password.email, test_password.email)
def test_copy_email(self): ''' Test to confirm that we are copying the email address from a found contact ''' self.new_password.save_password() Password.copy_email("0740772578") self.assertEqual(self.new_password.email, pyperclip.paste())
def test_password_exist(self): self.new_password.save_Password test_password = Password("flo", "boel", "flock", "7350") test_password.save_Password() password_exist = Password.password_exist("flock") self.assertTrue(password_exist)
def test_save_multiple_password(self): ''' test_save_multiple_password to check if we can save multiple password objects to our password-locker ''' self.new_password.save_password() test_password = Password("jasonmk", "RJXP2I5") test_password.save_password() self.assertEqual(len(Password.password_locker), 2)
def test_find_password_by_user_name(self): self.new_password.save_Password() test_password = Password("flo", "boel", "flock", "7350") test_password.save_Password() found_password = Password.find_by_user_name("flock") self.assertEqual(found_password.password, test_password.password)
def test_delete_password(self): ''' test_delete_password to test if we can remove a password from our password list ''' self.new_password.save_password() test_password = Password("Test","user","0746432419","*****@*****.**") # new password test_password.save_password() self.new_Password.delete_password()# Deleting a password object self.assertEqual(len(Password.password_list),1)
def test_delete_password(self): ''' test_delete_password to test if we can remove a password from our password list ''' self.new_password.save_password() test_password = Password("Micah", "Mutugi", "python") # new password test_password.save_password() self.new_password.delete_password() # Deleting a password object self.assertEqual(len(Password.password_list), 1)
def test_find_password_by_number(self): ''' test to check if we can find a password by phone number and display information ''' self.new_password.save_password() test_password = Password("Micah", "Mutugi", "python") # new password test_password.save_password() found_password = Password.find_by_number("python")
def test_delete_password(self): ''' test_delete_password to test if we can remove a password from our password_locker ''' self.new_password.save_password() test_password = Password("jasonmk", "RJXP2I5") test_password.save_password() self.new_password.delete_password() self.assertEqual(len(Password.password_locker), 1)
def create_cred(self, service, username, password=None): if password is None: password = Password.generate(mn=64) new_entry = { "username": username, "password": Password().encrypt(password).decode() } self.creds[service] = new_entry Pwdfile().write(self.creds)
def test_save_multiple_password(self): ''' test_save_multiple_contact to check if we can save multiple contact objects to our contact_list ''' self.new_password.save_password() test_password = Password("Test", "user", "0740772578", "*****@*****.**", "evracheche1999") # new contact test_password.save_password() self.assertEqual(len(Password.password_list), 2)
def test_password_exists(self): ''' test to check if we can return a Boolean if we cannot find the password. ''' self.new_password.save_password() test_password = Password("jasonmk", "RJXP2I5") test_password.save_password() password_exists = Password.password_exist("jasonmk") self.assertTrue(password_exists)
def test_delete_password(self): ''' test_delete_contact to test if we can remove a contact from our contact list ''' self.new_password.save_password() test_password = Password("Test", "user", "0740772575", "*****@*****.**", "evracheche1999") # new contact test_password.save_password() self.new_password.delete_password() # Deleting a contact object self.assertEqual(len(Password.password_list), 1)
def test_password_exists(self): ''' test to check if we can return a Boolean if we cannot find the contact. ''' self.new_password.save_password() test_password = Password("Micah", "Mutugi", "python") # new password test_password.save_password() password_exists = Password.password_exist("python") self.assertTrue(password_exists)
def download(download_hash): if not download_hash: return response(request, 'No download hash specified', 400) if re.search('[^A-Za-z0-9_]', download_hash): return response(request, 'invalid download hash', 400) fb = FbQuery() # fetch file f = fb.file_get(download_hash) if not f: return response(request, 'Could not find file', 404) if f.expire != '0': # Expire date exists if fb.file_expired(f.expire): # Remove expired file from storage and database fb.file_remove(download_hash, f.filename) return response(request, 'This download has expired', 410) if f.download_password: # This file is password protected. if request.method == 'POST': # Validate download_password from database with user input pw = Password(config.get('settings', 'secret_key')) if not pw.validate(f.download_password, request.form['password']): return render_template('download.html', error='Invalid Password') else: return render_template('download.html', error=None) if f.one_time_download: # Set expire date to current time, download will be invalid in a minute fb.file_set_expiry(download_hash, datetime.now().strftime('%Y%m%d%H%M%S')) # Serve images in browser type = guess_type( os.path.join(app.config['UPLOAD_FOLDER'], download_hash, f.filename))[0] attachment = True if type and 'image' in type: attachment = False # Serve file, everything is ok return send_from_directory(os.path.join(app.config['UPLOAD_FOLDER'], download_hash), f.filename, as_attachment=attachment, cache_timeout=0)
def __init__(self, name, type, defaults=None, **kwargs): super(Config, self).__init__(defaults=defaults, **kwargs) self._name = name self._type = type if self._type not in VIRTWHO_TYPES: raise InvalidOption('Invalid type "%s", must be one of following %s' % (self._type, ", ".join(VIRTWHO_TYPES))) for password_option, decrypted_option in self.PASSWORD_OPTIONS: try: pwd = self._options[password_option] except KeyError: continue try: self._options[decrypted_option] = Password.decrypt(unhexlify(pwd)) except (TypeError, IndexError): raise InvalidPasswordFormat( "Option \"{option}\" in config named \"{name}\" can't be decrypted, possibly corrupted" .format(option=password_option, name=name)) for old_name, new_name in self.RENAMED_OPTIONS: try: self._options[new_name] = self._options[old_name] except KeyError: pass for option in self.LATIN1_OPTIONS: value = self._options.get(option) if not value: continue try: value.encode('latin1') except UnicodeDecodeError: raise InvalidOption("Option '{}' is not in latin1 encoding".format(option))
def fromParser(self, name, parser): type = parser.get(name, "type").lower() server = username = password = owner = env = None if type != 'libvirt': server = parser.get(name, "server") username = parser.get(name, "username") try: password = parser.get(name, "password") except NoOptionError: password = None if password is None: try: crypted = parser.get(name, "encrypted_password") password = Password.decrypt(crypted) except NoOptionError: password = None try: owner = parser.get(name, "owner") except NoOptionError: owner = None try: env = parser.get(name, "env") except NoOptionError: env = None return Config(name, type, server, username, password, owner, env)
def testDecrypt(self): self.assertEqual( Password._crypt( Password.DECRYPT, '06a9214036b8a15b512e03d534120006', '3dafba429d9eb430b422da802c9fac41', unhexlify('e353779c1079aeb82708942dbe77181a')), 'Single block msg')
def testCryptedPassword(self, password): from password import Password password.return_value = (hexlify(Password._generate_key()), hexlify(Password._generate_key())) passwd = "TestSecretPassword!" crypted = hexlify(Password.encrypt(passwd)) filename = os.path.join(self.config_dir, "test.conf") with open(filename, "w") as f: f.write(""" [test] type=esx server=1.2.3.4 username=admin encrypted_password=%s owner=root env=staging """ % crypted) manager = ConfigManager(self.logger, self.config_dir) self.assertEqual(len(manager.configs), 1) self.assertEqual(manager.configs[0].password, passwd)
def _get_password(self, option_name, encryped_option_name): pwd = self._options.get(option_name, None) if pwd is None: encrypted_password = self._options.get(encryped_option_name, None) if encrypted_password is None: return None try: pwd = Password.decrypt(unhexlify(encrypted_password)) except TypeError: raise InvalidPasswordFormat("Password can't be decrypted, possibly corrupted") return pwd
def _read_password(self, name, parser): try: password = parser.get(name, "password") except NoOptionError: password = None if password is None: try: crypted = parser.get(name, "encrypted_password") password = Password.decrypt(password) except NoOptionError: return None
def _login(self): self._reload() self._open() self._select_form("login_form") password = Password.get(self.user) # @TODO remove password = password.replace("\n", "") self.user = self.user.replace("\n", "") self.browser["name"] = self.user self.browser["pass"] = password return self.browser.submit()
def get_current_user(self): """Set current user, authenticated via HTTP basic auth""" auth_header = self.request.headers.get('Authorization') if auth_header is None or not auth_header.startswith('Basic '): return None auth_decoded = base64.decodestring(auth_header[6:]) if not auth_decoded.count(':'): return None login, password = auth_decoded.split(':', 2) if not login or not password: return None try: encrypted_password = self.mongo.user.find_one({'_id': login}, {'password': 1})['password'] except: return None if encrypted_password and Password.verify(password, encrypted_password): return login else: return None
def fromParser(self, name, parser): type = parser.get(name, "type").lower() server = username = password = owner = env = None try: server = parser.get(name, "server") except NoOptionError: # Use '' as libvirt url when not given, for backward compatibility if type == 'libvirt': server = '' else: raise try: username = parser.get(name, "username") except NoOptionError: username = None try: password = parser.get(name, "password") except NoOptionError: password = None if password is None: try: crypted = parser.get(name, "encrypted_password") password = Password.decrypt(unhexlify(crypted)) except NoOptionError: password = None try: owner = parser.get(name, "owner") except NoOptionError: owner = None try: env = parser.get(name, "env") except NoOptionError: env = None return Config(name, type, server, username, password, owner, env)
def test_not_has_two_pairs(self): self.assertEqual(False, Password.containTwoPairsOfLetters("aaaaaaaa")) self.assertEqual(False, Password.containTwoPairsOfLetters("aaaaaaab")) self.assertEqual(False, Password.containTwoPairsOfLetters("baaaaaab")) self.assertEqual(False, Password.containTwoPairsOfLetters("abababab")) self.assertEqual(False, Password.containTwoPairsOfLetters("aaaacbaa"))
def test_problem_input(self): self.assertEqual(True, Password.containTwoPairsOfLetters("abbceffg")) self.assertEqual(False, Password.containTwoPairsOfLetters("abbcegjk"))
print """Utility that encrypts passwords for virt-who. Enter password that should be encrypted. This encrypted password then can be supplied to virt-who configuration. This command must be executed as root! WARNING: root user can still decrypt encrypted passwords! """ sys.exit(0) if os.getuid() != 0: print >> sys.stderr, "Only root can encrypt passwords" sys.exit(1) try: pwd = getpass("Password: "******"Keyfile %s doesn't exist and can't be created, rerun as root" % Password.KEYFILE sys.exit(1) except InvalidKeyFile: print >> sys.stderr, "Can't access keyfile %s, rerun as root" % Password.KEYFILE sys.exit(1) print >> sys.stderr, "Use following as value for encrypted_password key in the configuration file:" print hexlify(enc)
def main(): parser = OptionParser(usage="%prog <template> [options]") # Defaulted parser.add_option("-c", "--config", dest="config", help="full path to YAML config file", default=Config.DEFAULT_CONFIG_FILE) # Defaulted parser.add_option("-a", "--all", dest="auto_all", action="store_true", help="automatically create all of the subtasks in the template") # One of these is required parser.add_option("-s", "--story", dest="story" , help="Story text to use for the parent story") parser.add_option("-i", "--issue", dest="issue", help="JIRA Issue to create all the subtasks under") # Most likely in config.yaml, but overridable parser.add_option("-e", "--assignee", dest="assignee", help="username of JIRA user to assign tasks and subtasks to") parser.add_option("-p", "--project_id", dest="project_id", help="name of template to work from") parser.add_option("-j", "--jira", dest="jira", help="JIRA api URL") parser.add_option("-u", "--username", dest="username", help="username to log into JIRA with") # Most likely defaulted, but possibly from config.yaml parser.add_option("-d", "--template_dir", dest="template_dir", help="name of template to work from") (options, args) = parser.parse_args() if len(args) != 1: die('template name not given') if not os.path.isfile(options.config): die("Config file '%s' does not exist or is not a file" % options.config) if not os.access(options.config, os.R_OK): die("Config file '%s' is not readable" % options.config) if options.story is None and options.issue is None: die("You must specify either a JIRA story (-s, --story) to create or a JIRA issue (-i, --issue) to modify") template=args[0] with open(options.config, 'r') as config_yaml: config_dict = yaml.load(config_yaml) password = Password() config = Config(password.password, template, options, config_dict) options = { 'server': config.jira, 'rest_api_version' : "latest", } jira = JIRA(options, basic_auth=(config.username, config.password)) template = Template(jira, config.assignee, config.template_dir, config.template, config.auto_all, config_dict["issue_config"]) if config.is_story(): print "Creating story with description: '%s'" % config.story parent = jira.create_issue(config.story) else: print "Adding sub-tasks to issue: '%s'" % config.issue parent = jira.issue(config.issue) print parent print parent.fields.project.key subtasks = template.add_subtasks(parent) for subtask in subtasks: print subtask password.cache_password()
def test_from_problem(self): self.assertEqual(True, Password.isValid("abcdffaa"))
def testBackslash(self): self.mock_pwd_file() pwd = 'abc\\def' self.assertEqual( Password.decrypt(Password.encrypt(pwd)), pwd)
def test_from_problem(self): self.assertEqual("abcdffaa", Password.getNextPassword("abcdefgh")) # takes 3 minutes to run self.assertEqual("ghjaabcc", Password.getNextPassword("ghijklmn"))
def testUnpad(self): self.assertEqual(hexlify(Password._unpad(unhexlify("00010203040506070809060606060606"))), "00010203040506070809")
from password import Password userInput = '' userPassword = Password() while userInput != ":q!": userInput = input("Enter Password\n") userPassword.setPassword(userInput) userPassword.calculateScore() #userPassword.printReport() userPassword.printScore()
from password import Password #part 1 print (Password.getNextPassword("vzbxkghb")) #part 2 print (Password.getNextPassword(Password.getNextPassword("vzbxkghb")))
def test_one_rollover(self): result = Password.increment("aaaaaaaz") self.assertEqual("aaaaaaba", result)
def fromParser(self, name, parser): type = parser.get(name, "type").lower() server = username = password = owner = env = rhsm_username = rhsm_password = None try: server = parser.get(name, "server") except NoOptionError: # Use '' as libvirt url when not given, for backward compatibility if type in ["libvirt", "vdsm", "fake"]: server = "" else: raise try: username = parser.get(name, "username") except NoOptionError: username = None try: password = parser.get(name, "password") except NoOptionError: try: encrypted_password = parser.get(name, "encrypted_password") password = Password.decrypt(unhexlify(encrypted_password)) except TypeError: raise InvalidPasswordFormat("Password can't be decrypted, possibly corrupted") except NoOptionError: password = None try: owner = parser.get(name, "owner") except NoOptionError: owner = None try: env = parser.get(name, "env") except NoOptionError: env = None try: rhsm_username = parser.get(name, "rhsm_username") except NoOptionError: rhsm_username = None try: rhsm_password = parser.get(name, "rhsm_password") except NoOptionError: rhsm_password = None # Only attempt to get the encrypted rhsm password if we have a username: if rhsm_username is not None and rhsm_password is None: try: encrypted_rhsm_password = parser.get(name, "rhsm_encrypted_password") rhsm_password = Password.decrypt(unhexlify(encrypted_rhsm_password)) except NoOptionError: rhsm_password = None try: rhsm_hostname = parser.get(name, "rhsm_hostname") except NoOptionError: rhsm_hostname = None try: rhsm_port = parser.get(name, "rhsm_port") except NoOptionError: rhsm_port = None try: rhsm_prefix = parser.get(name, "rhsm_prefix") except NoOptionError: rhsm_prefix = None try: rhsm_proxy_hostname = parser.get(name, "rhsm_proxy_hostname") except NoOptionError: rhsm_proxy_hostname = None try: rhsm_proxy_port = parser.get(name, "rhsm_proxy_port") except NoOptionError: rhsm_proxy_port = None try: rhsm_proxy_user = parser.get(name, "rhsm_proxy_user") except NoOptionError: rhsm_proxy_user = None try: rhsm_proxy_password = parser.get(name, "rhsm_proxy_password") except NoOptionError: try: encrypted_password = parser.get(name, "rhsm_encrypted_proxy_password") rhsm_proxy_password = Password.decrypt(unhexlify(encrypted_password)) except TypeError: raise InvalidPasswordFormat("RHSM proxy password can't be decrypted, possibly corrupted") except NoOptionError: rhsm_proxy_password = None try: rhsm_insecure = parser.get(name, "rhsm_insecure") except NoOptionError: rhsm_insecure = None config = Config( name, type, server, username, password, owner, env, rhsm_username, rhsm_password, rhsm_hostname, rhsm_port, rhsm_prefix, rhsm_proxy_hostname, rhsm_proxy_port, rhsm_proxy_user, rhsm_proxy_password, rhsm_insecure, ) try: config.hypervisor_id = parser.get(name, "hypervisor_id") except NoOptionError: config.hypervisor_id = "uuid" try: config.filter_host_uuids = parse_list(parser.get(name, "filter_host_uuids")) except NoOptionError: config.filter_host_uuids = None try: config.exclude_host_uuids = parse_list(parser.get(name, "exclude_host_uuids")) except NoOptionError: config.exclude_host_uuids = None if type == "esx": try: config.esx_simplified_vim = parser.get(name, "simplified_vim").lower() not in ("0", "false", "no") except NoOptionError: pass try: config.filter_host_parents = parse_list(parser.get(name, "filter_host_parents")) except NoOptionError: config.filter_host_parents = None try: config.exclude_host_parents = parse_list(parser.get(name, "exclude_host_parents")) except NoOptionError: config.exclude_host_parents = None elif type == "fake": try: config.fake_is_hypervisor = parser.get(name, "is_hypervisor").lower() not in ("0", "false", "no") except NoOptionError: pass config.fake_file = parser.get(name, "file") return config
def test_has_two_pairs(self): self.assertEqual(True, Password.containTwoPairsOfLetters("aabbqwer")) self.assertEqual(True, Password.containTwoPairsOfLetters("aaxbbqwe")) self.assertEqual(True, Password.containTwoPairsOfLetters("bbqweraa")) self.assertEqual(True, Password.containTwoPairsOfLetters("qwerxxaa"))
def test_problem_input(self): self.assertEqual(True, Password.containsInvalidCharacter("hijklmmn"))
def test_Password___test_lenght(self): password = Password('admin0') self.assertFalse(password._Password___check_password())
def test_valid(self): self.assertEqual(False, Password.containsInvalidCharacter("aaabaaaa"))
def testBoth(self): self.mock_pwd_file() pwd = "Test password" encrypted = Password.encrypt(pwd) self.assertEqual(pwd, Password.decrypt(encrypted))
def testCryptedPasswordWithoutKey(self): from password import Password, InvalidKeyFile Password.KEYFILE = "/some/nonexistant/file" passwd = "TestSecretPassword!" with self.assertRaises(InvalidKeyFile): Password.decrypt(unhexlify("06a9214036b8a15b512e03d534120006"))
def testPercent(self): self.mock_pwd_file() pwd = 'abc%%def' self.assertEqual( Password.decrypt(Password.encrypt(pwd)), pwd)
def testBoth(self): f, filename = tempfile.mkstemp() self.addCleanup(os.unlink, filename) Password.KEYFILE = filename pwd = "Test password" Password._can_write = MagicMock(retun_value=True) encrypted = Password.encrypt(pwd) self.assertEqual(pwd, Password.decrypt(encrypted))