本文整理汇总了Python中twisted.cred.credentials.checkPassword方法的典型用法代码示例。如果您正苦于以下问题:Python credentials.checkPassword方法的具体用法?Python credentials.checkPassword怎么用?Python credentials.checkPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.cred.credentials
的用法示例。
在下文中一共展示了credentials.checkPassword方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestAvatarId
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def requestAvatarId(self, c):
try:
u, p = self.getUser(c.username)
except KeyError:
return defer.fail(error.UnauthorizedLogin())
else:
up = credentials.IUsernamePassword(c, None)
if self.hash:
if up is not None:
h = self.hash(up.username, up.password, p)
if h == p:
return defer.succeed(u)
return defer.fail(error.UnauthorizedLogin())
else:
return defer.maybeDeferred(c.checkPassword, p
).addCallback(self._cbPasswordMatch, u)
# For backwards compatibility
# Allow access as the old name.
示例2: assertServerAuthenticated
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def assertServerAuthenticated(self, loginArgs, username="username", password="password"):
"""
Assert that a login attempt has been made, that the credentials and
interfaces passed to it are correct, and that when the login request
is satisfied, a successful response is sent by the ESMTP server
instance.
@param loginArgs: A C{list} previously passed to L{portalFactory}.
"""
d, credentials, mind, interfaces = loginArgs.pop()
self.assertEqual(loginArgs, [])
self.assertTrue(twisted.cred.credentials.IUsernamePassword.providedBy(credentials))
self.assertEqual(credentials.username, username)
self.assertTrue(credentials.checkPassword(password))
self.assertIn(smtp.IMessageDeliveryFactory, interfaces)
self.assertIn(smtp.IMessageDelivery, interfaces)
d.callback((smtp.IMessageDeliveryFactory, None, lambda: None))
self.assertEqual(
["235 Authentication successful."],
self.transport.value().splitlines())
示例3: assertServerAuthenticated
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def assertServerAuthenticated(self, loginArgs, username=b"username",
password=b"password"):
"""
Assert that a login attempt has been made, that the credentials and
interfaces passed to it are correct, and that when the login request
is satisfied, a successful response is sent by the ESMTP server
instance.
@param loginArgs: A C{list} previously passed to L{portalFactory}.
@param username: The login user.
@param password: The login password.
"""
d, credentials, mind, interfaces = loginArgs.pop()
self.assertEqual(loginArgs, [])
self.assertTrue(twisted.cred.credentials.IUsernamePassword.providedBy(credentials))
self.assertEqual(credentials.username, username)
self.assertTrue(credentials.checkPassword(password))
self.assertIn(smtp.IMessageDeliveryFactory, interfaces)
self.assertIn(smtp.IMessageDelivery, interfaces)
d.callback((smtp.IMessageDeliveryFactory, None, lambda: None))
self.assertEqual(
[b"235 Authentication successful."],
self.transport.value().splitlines())
示例4: requestAvatarId
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def requestAvatarId(self, c):
try:
u, p = self.getUser(c.username)
except KeyError:
return defer.fail(error.UnauthorizedLogin())
else:
up = credentials.IUsernamePassword(c, None)
if self.hash:
if up is not None:
h = self.hash(up.username, up.password, p)
if h == p:
return defer.succeed(u)
return defer.fail(error.UnauthorizedLogin())
else:
return defer.maybeDeferred(c.checkPassword, p
).addCallback(self._cbPasswordMatch, u)
示例5: assertServerAuthenticated
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def assertServerAuthenticated(self, loginArgs, username="username", password="password"):
"""
Assert that a login attempt has been made, that the credentials and
interfaces passed to it are correct, and that when the login request
is satisfied, a successful response is sent by the ESMTP server
instance.
@param loginArgs: A C{list} previously passed to L{portalFactory}.
"""
d, credentials, mind, interfaces = loginArgs.pop()
self.assertEqual(loginArgs, [])
self.failUnless(twisted.cred.credentials.IUsernamePassword.providedBy(credentials))
self.assertEqual(credentials.username, username)
self.failUnless(credentials.checkPassword(password))
self.assertIn(smtp.IMessageDeliveryFactory, interfaces)
self.assertIn(smtp.IMessageDelivery, interfaces)
d.callback((smtp.IMessageDeliveryFactory, None, lambda: None))
self.assertEqual(
["235 Authentication successful."],
self.transport.value().splitlines())
示例6: requestAvatarId
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def requestAvatarId(self, credentials):
username = credentials.username
if username in self.tokens:
if credentials.checkPassword(self.tokens[username]):
return defer.succeed(username)
else:
return defer.fail(
credError.UnauthorizedLogin("Bad session token"))
else:
return defer.fail(
credError.UnauthorizedLogin("No such user"))
示例7: requestAvatarId
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def requestAvatarId(self, credentials):
return defer.maybeDeferred(
credentials.checkPassword, self.users[credentials.username]
).addCallback(self._cbCheck, credentials.username)
示例8: requestAvatarId
# 需要导入模块: from twisted.cred import credentials [as 别名]
# 或者: from twisted.cred.credentials import checkPassword [as 别名]
def requestAvatarId(self, credentials):
if credentials.username in self.users:
return defer.maybeDeferred(
credentials.checkPassword, self.users[credentials.username]
).addCallback(self._cbCheck, credentials.username)