本文整理匯總了Python中crypt.mksalt方法的典型用法代碼示例。如果您正苦於以下問題:Python crypt.mksalt方法的具體用法?Python crypt.mksalt怎麽用?Python crypt.mksalt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類crypt
的用法示例。
在下文中一共展示了crypt.mksalt方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _generate_salt
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def _generate_salt(self):
# The salt can be generated with crypt.mksalt() on Python 3
CHARACTERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
salt = ''.join(random.choice(CHARACTERS) for i in range(16))
# Use SHA512
return '$6$' + salt
示例2: gen_htpasswd
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def gen_htpasswd(users_passwords, file_name_suffix=""):
with open("nginx/.htpasswd" + file_name_suffix, "w") as fh:
for user, password in users_passwords.items():
if not password:
fh.write("\n")
else:
fh.write(
"%s:%s\n"
% (
user,
crypt.crypt(
password, crypt.mksalt(crypt.METHOD_SHA512)
),
)
)
示例3: password
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def password(self,new_pw):
if new_pw!=self.password_hash:
import argon2
import crypt
import base64
self.password_salt = crypt.mksalt()+crypt.mksalt()+crypt.mksalt()+crypt.mksalt()+crypt.mksalt()
hash = argon2.argon2_hash(new_pw, self.password_salt)
self.password_hash = base64.b64encode(hash).decode("UTF-8")
示例4: generate_token
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def generate_token():
import crypt
return str(crypt.mksalt()+crypt.mksalt())
示例5: encrypt_password
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def encrypt_password(entry):
return crypt.crypt(entry, crypt.mksalt(crypt.METHOD_SHA512))
示例6: set_root_password
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def set_root_password(args: CommandLineArguments, root: str, do_run_build_script: bool, for_cache: bool) -> None:
"Set the root account password, or just delete it so it's easy to log in"
if do_run_build_script:
return
if for_cache:
return
if args.password == '':
with complete_step("Deleting root password"):
def jj(line: str) -> str:
if line.startswith('root:'):
return ':'.join(['root', ''] + line.split(':')[2:])
return line
patch_file(os.path.join(root, 'etc/passwd'), jj)
elif args.password:
with complete_step("Setting root password"):
if args.password_is_hashed:
password = args.password
else:
password = crypt.crypt(args.password, crypt.mksalt(crypt.METHOD_SHA512))
def jj(line: str) -> str:
if line.startswith('root:'):
return ':'.join(['root', password] + line.split(':')[2:])
return line
patch_file(os.path.join(root, 'etc/shadow'), jj)
示例7: set_user_passwd
# 需要導入模塊: import crypt [as 別名]
# 或者: from crypt import mksalt [as 別名]
def set_user_passwd(params):
"""
test API for setUserPassword in class virDomain
"""
logger = params['logger']
guest = params['guestname']
username = params['username']
userpasswd = params['userpassword']
if 'flags' in params:
if params['flags'] == 'encrypted':
flags = libvirt.VIR_DOMAIN_PASSWORD_ENCRYPTED
else:
flags = 0
else:
flags = 0
try:
if 'conn' in params:
conn = libvirt.open(params['conn'])
else:
conn = libvirt.open(optional_params['conn'])
logger.info("get connection to libvirtd")
vm = conn.lookupByName(guest)
logger.info("test guest name: %s" % guest)
if not check_agent_status(vm):
logger.error("guest agent is not connected")
return 1
mac = get_guest_mac(vm)
if not mac:
logger.error("cannot get guest interface mac")
return 1
ipaddr = utils.mac_to_ip(mac, 180)
if not ipaddr:
logger.error("cannot get guest IP")
return 1
if flags > 0:
passwd = crypt.crypt("123456", crypt.mksalt(crypt.METHOD_SHA512))
else:
passwd = "123456"
if create_new_user(ipaddr, "usertestapi", username, userpasswd, logger) != 0:
return 1
vm.setUserPassword("usertestapi", passwd, flags)
if verify_cur_user(ipaddr, "usertestapi", "123456") != 0:
logger.error("cannot login guest via new user")
return 1
except libvirtError as e:
logger.error("API error message: %s" % e.get_error_message())
return 1
return 0