当前位置: 首页>>代码示例>>Python>>正文


Python crypt.mksalt方法代码示例

本文整理汇总了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 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:8,代码来源:password_manager.py

示例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)
                        ),
                    )
                ) 
开发者ID:mendix,项目名称:cf-mendix-buildpack,代码行数:17,代码来源:nginx.py

示例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") 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:10,代码来源:model.py

示例4: generate_token

# 需要导入模块: import crypt [as 别名]
# 或者: from crypt import mksalt [as 别名]
def generate_token():
        import crypt
        return str(crypt.mksalt()+crypt.mksalt()) 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:5,代码来源:model.py

示例5: encrypt_password

# 需要导入模块: import crypt [as 别名]
# 或者: from crypt import mksalt [as 别名]
def encrypt_password(entry):

    return crypt.crypt(entry, crypt.mksalt(crypt.METHOD_SHA512)) 
开发者ID:redhat-cop,项目名称:infra-ansible,代码行数:5,代码来源:encrypt_password.py

示例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) 
开发者ID:systemd,项目名称:mkosi,代码行数:29,代码来源:mkosi.py

示例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 
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:63,代码来源:set_user_passwd.py


注:本文中的crypt.mksalt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。