本文整理汇总了Python中win32security.LogonUser方法的典型用法代码示例。如果您正苦于以下问题:Python win32security.LogonUser方法的具体用法?Python win32security.LogonUser怎么用?Python win32security.LogonUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32security
的用法示例。
在下文中一共展示了win32security.LogonUser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logonUser
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LogonUser [as 别名]
def logonUser(loginString):
"""
Login as specified user and return handle.
loginString: 'Domain\nUser\nPassword'; for local
login use . or empty string as domain
e.g. '.\nadministrator\nsecret_password'
"""
domain, user, passwd = loginString.split('\n')
return win32security.LogonUser(
user,
domain,
passwd,
win32con.LOGON32_LOGON_INTERACTIVE,
win32con.LOGON32_PROVIDER_DEFAULT
)
示例2: validate_authentication
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LogonUser [as 别名]
def validate_authentication(self, username, password, handler):
if username == "anonymous":
if self.anonymous_user is None:
raise AuthenticationFailed(self.msg_anon_not_allowed)
return
try:
win32security.LogonUser(username, None, password,
win32con.LOGON32_LOGON_INTERACTIVE,
win32con.LOGON32_PROVIDER_DEFAULT)
except pywintypes.error:
raise AuthenticationFailed(self.msg_wrong_password)
示例3: impersonate_user
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LogonUser [as 别名]
def impersonate_user(self, username, password):
"""Impersonate the security context of another user."""
handler = win32security.LogonUser(
username, None, password,
win32con.LOGON32_LOGON_INTERACTIVE,
win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(handler)
handler.Close()
示例4: impersonate
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LogonUser [as 别名]
def impersonate(username, password, domain):
if username:
print "Using alternative credentials:"
print "Username: " + str(username)
print "Password: " + str(password)
print "Domain: " + str(domain)
handle = win32security.LogonUser( username, domain, password, win32security.LOGON32_LOGON_NEW_CREDENTIALS, win32security.LOGON32_PROVIDER_WINNT50 )
win32security.ImpersonateLoggedOnUser( handle )
else:
print "Running as current user. No logon creds supplied (-u, -d, -p)."
print
示例5: impersonate_user
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LogonUser [as 别名]
def impersonate_user(self, username, password):
"""impersonate user when operating file system
"""
handler = win32security.LogonUser(
username, None, password,
win32con.LOGON32_LOGON_INTERACTIVE,
win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(handler)
handler.Close()
示例6: nt_log_on
# 需要导入模块: import win32security [as 别名]
# 或者: from win32security import LogonUser [as 别名]
def nt_log_on(domain, username, password):
"""
This feature is experimental for windows hosts that want to authenticate on the
local machines domain running this application.
# todo: This will eventually be changed to use ldap but I don't currently have a means to test this.
:param domain:
:param username:
:param password:
:return:
"""
valid_os = False
authenticated = False
if os.name == 'nt':
try:
import pywintypes
import win32security
valid_os = True
except ModuleNotFoundError:
raise ModuleNotFoundError('Is pywin32 installed?')
if valid_os:
try:
token = win32security.LogonUser(
username,
domain,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT)
authenticated = bool(token)
except pywintypes.error:
pass
return authenticated