本文整理匯總了Python中password.Password類的典型用法代碼示例。如果您正苦於以下問題:Python Password類的具體用法?Python Password怎麽用?Python Password使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Password類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testBoth
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)
示例2: testBoth
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))
示例3: fromParser
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)
示例4: testDecrypt
def testDecrypt(self):
self.assertEqual(
Password._crypt(
Password.DECRYPT,
'06a9214036b8a15b512e03d534120006',
'3dafba429d9eb430b422da802c9fac41',
unhexlify('e353779c1079aeb82708942dbe77181a')),
'Single block msg')
示例5: testCryptedPassword
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)
示例6: _read_password
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
示例7: _get_password
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
示例8: _login
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()
示例9: get_current_user
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
示例10: fromParser
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)
示例11: testPercent
def testPercent(self):
self.mock_pwd_file()
pwd = 'abc%%def'
self.assertEqual(
Password.decrypt(Password.encrypt(pwd)),
pwd)
示例12: testUnpad
def testUnpad(self):
self.assertEqual(hexlify(Password._unpad(unhexlify("00010203040506070809060606060606"))), "00010203040506070809")
示例13: testBoth
def testBoth(self):
self.mock_pwd_file()
pwd = "Test password"
encrypted = Password.encrypt(pwd)
self.assertEqual(pwd, Password.decrypt(encrypted))
示例14: test_problem_input
def test_problem_input(self):
self.assertEqual(True, Password.containTwoPairsOfLetters("abbceffg"))
self.assertEqual(False, Password.containTwoPairsOfLetters("abbcegjk"))
示例15: test_from_problem
def test_from_problem(self):
self.assertEqual(True, Password.isValid("abcdffaa"))