本文整理匯總了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