本文整理汇总了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