本文整理匯總了Python中passlib.hash.sha512_crypt.hash方法的典型用法代碼示例。如果您正苦於以下問題:Python sha512_crypt.hash方法的具體用法?Python sha512_crypt.hash怎麽用?Python sha512_crypt.hash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類passlib.hash.sha512_crypt
的用法示例。
在下文中一共展示了sha512_crypt.hash方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _encode_secret
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def _encode_secret(attribute, new_value=None):
if attribute == 'NT-Password':
attribute_value = nthash.hash(new_value)
elif attribute == 'LM-Password':
attribute_value = lmhash.hash(new_value)
elif attribute == 'MD5-Password':
attribute_value = md5(new_value.encode('utf-8')).hexdigest()
elif attribute == 'SMD5-Password':
salt = urandom(4)
hash = md5(new_value.encode('utf-8'))
hash.update(salt)
hash_encoded = encodestring(hash.digest() + salt)
attribute_value = hash_encoded.decode('utf-8')[:-1]
elif attribute == 'SHA-Password':
attribute_value = sha1(new_value.encode('utf-8')).hexdigest()
elif attribute == 'SSHA-Password':
salt = urandom(4)
hash = sha1(new_value.encode('utf-8'))
hash.update(salt)
hash_encoded = encodestring(hash.digest() + salt)
attribute_value = hash_encoded.decode('utf-8')[:-1]
elif attribute == 'Crypt-Password':
attribute_value = sha512_crypt.hash(new_value)
else:
attribute_value = new_value
return attribute_value
示例2: hash
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def hash(a):
h = sha512_crypt.hash(a)
return h
示例3: bf
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def bf(h, dictionary):
f = open(dictionary, 'r')
lines = f.readlines()
print('\033[1;34m[*]\033[0m Starting Brute Force - hash = ' + h)
for i in lines:
h2 = sha512_crypt.hash(i[:-1])
if h == h2:
print('\033[1;32m[+]\033[0m Hash Cracked! - Password = ' + i)
exit()
print('\033[1;31m[-]\033[0m Hash could not be cracked!')
示例4: get_config
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def get_config(
cluster_representation: ClusterRepresentation,
extra_config: Dict[str, Any],
dcos_variant: DCOSVariant,
security_mode: Optional[str],
license_key: Optional[Path],
) -> Dict[str, Any]:
"""
Get a DC/OS configuration to use for the given cluster.
"""
is_enterprise = bool(dcos_variant == DCOSVariant.ENTERPRISE)
if is_enterprise:
superuser_username = DEFAULT_SUPERUSER_USERNAME
superuser_password = DEFAULT_SUPERUSER_PASSWORD
enterprise_extra_config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
'fault_domain_enabled': False,
}
if license_key is not None:
key_contents = license_key.read_text()
enterprise_extra_config['license_key_contents'] = key_contents
extra_config = {**enterprise_extra_config, **extra_config}
if security_mode is not None:
extra_config['security'] = security_mode
dcos_config = {
**cluster_representation.base_config,
**extra_config,
}
return dcos_config
示例5: test_enterprise
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def test_enterprise(
self,
cluster_backend: ClusterBackend,
enterprise_1_9_installer: Path,
) -> None:
"""
A DC/OS Enterprise 1.9 cluster can be started.
"""
superuser_username = str(uuid.uuid4())
superuser_password = str(uuid.uuid4())
config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
}
with Cluster(cluster_backend=cluster_backend) as cluster:
cluster.install_dcos_from_path(
dcos_installer=enterprise_1_9_installer,
dcos_config={
**cluster.base_config,
**config,
},
output=Output.LOG_AND_CAPTURE,
ip_detect_path=cluster_backend.ip_detect_path,
)
cluster.wait_for_dcos_ee(
superuser_username=superuser_username,
superuser_password=superuser_password,
)
for node in {
*cluster.masters,
*cluster.agents,
*cluster.public_agents,
}:
build = node.dcos_build_info()
assert build.version.startswith('1.9')
assert build.commit
assert build.variant == DCOSVariant.ENTERPRISE
示例6: calico_ipip_cluster
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def calico_ipip_cluster(docker_backend: Docker, artifact_path: Path,
request: SubRequest, log_dir: Path) -> Iterator[Cluster]:
with Cluster(
cluster_backend=docker_backend,
masters=1,
agents=2,
public_agents=1,
) as cluster:
config = {
"superuser_username": superuser_username,
# We can hash the password with any `passlib`-based method here.
# We choose `sha512_crypt` arbitrarily.
"superuser_password_hash": sha512_crypt.hash(superuser_password),
"calico_vxlan_enabled": "false",
"calico_network_cidr": "192.168.128.0/17",
}
cluster.install_dcos_from_path(
dcos_installer=artifact_path,
dcos_config={
**cluster.base_config,
**config,
},
output=Output.LOG_AND_CAPTURE,
ip_detect_path=docker_backend.ip_detect_path,
)
wait_for_dcos_oss(
cluster=cluster,
request=request,
log_dir=log_dir,
)
yield cluster
示例7: _enterprise_distribution_test
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def _enterprise_distribution_test(
distribution: Distribution,
enterprise_installer: Path,
license_key_contents: str,
) -> None:
"""
Assert that given a ``linux_distribution``, a DC/OS Enterprise ``Cluster``
with the Linux distribution is started.
We use this rather than pytest parameterization so that we can separate
the tests in ``.travis.yml``.
"""
superuser_username = str(uuid.uuid4())
superuser_password = str(uuid.uuid4())
config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
'fault_domain_enabled': False,
'license_key_contents': license_key_contents,
}
cluster_backend = Docker(linux_distribution=distribution)
with Cluster(
cluster_backend=cluster_backend,
masters=1,
agents=0,
public_agents=0,
) as cluster:
cluster.install_dcos_from_path(
dcos_installer=enterprise_installer,
dcos_config={
**cluster.base_config,
**config,
},
ip_detect_path=cluster_backend.ip_detect_path,
output=Output.CAPTURE,
)
cluster.wait_for_dcos_ee(
superuser_username=superuser_username,
superuser_password=superuser_password,
)
(master, ) = cluster.masters
node_distribution = _get_node_distribution(node=master)
assert node_distribution == distribution
示例8: test_run_enterprise_integration_test
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def test_run_enterprise_integration_test(
self,
ee_installer_url: str,
license_key_contents: str,
linux_distribution: Distribution,
) -> None:
"""
It is possible to run DC/OS integration tests on AWS.
This test module only requires a single master node.
"""
superuser_username = str(uuid.uuid4())
superuser_password = str(uuid.uuid4())
config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
'fault_domain_enabled': False,
'license_key_contents': license_key_contents,
'security': 'strict',
}
cluster_backend = AWS(linux_distribution=linux_distribution)
with Cluster(
cluster_backend=cluster_backend,
masters=1,
) as cluster:
cluster.install_dcos_from_url(
dcos_installer=ee_installer_url,
dcos_config={
**cluster.base_config,
**config,
},
output=Output.LOG_AND_CAPTURE,
ip_detect_path=cluster_backend.ip_detect_path,
)
cluster.wait_for_dcos_ee(
superuser_username=superuser_username,
superuser_password=superuser_password,
)
# No error is raised with a successful command.
# We choose a test file which runs very quickly.
fast_test_file = 'test_marathon_authn_authz.py'
cluster.run_with_test_environment(
args=['pytest', '-vvv', '-s', '-x', fast_test_file],
env={
'DCOS_LOGIN_UNAME': superuser_username,
'DCOS_LOGIN_PW': superuser_password,
},
output=Output.LOG_AND_CAPTURE,
)
示例9: _enterprise_distribution_test
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def _enterprise_distribution_test(
distribution: Distribution,
ee_installer_url: str,
license_key_contents: str,
) -> None:
"""
Assert that given a ``linux_distribution``, a DC/OS Enterprise ``Cluster``
with the Linux distribution is started.
We use this rather than pytest parameterization so that we can separate
the tests in ``.travis.yml``.
"""
superuser_username = str(uuid.uuid4())
superuser_password = str(uuid.uuid4())
config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
'fault_domain_enabled': False,
'license_key_contents': license_key_contents,
}
cluster_backend = AWS(linux_distribution=distribution)
with Cluster(
cluster_backend=cluster_backend,
masters=1,
agents=0,
public_agents=0,
) as cluster:
cluster.install_dcos_from_url(
dcos_installer=ee_installer_url,
dcos_config={
**cluster.base_config,
**config,
},
ip_detect_path=cluster_backend.ip_detect_path,
output=Output.CAPTURE,
)
cluster.wait_for_dcos_ee(
superuser_username=superuser_username,
superuser_password=superuser_password,
)
(master, ) = cluster.masters
node_distribution = _get_node_distribution(node=master)
assert node_distribution == distribution
示例10: test_run_pytest
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def test_run_pytest(
self,
cluster_backend: ClusterBackend,
enterprise_installer: Path,
license_key_contents: str,
) -> None:
"""
Integration tests can be run with `pytest`.
Errors are raised from `pytest`.
"""
superuser_username = str(uuid.uuid4())
superuser_password = str(uuid.uuid4())
config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
'fault_domain_enabled': False,
'license_key_contents': license_key_contents,
}
with Cluster(cluster_backend=cluster_backend) as cluster:
cluster.install_dcos_from_path(
dcos_installer=enterprise_installer,
dcos_config={
**cluster.base_config,
**config,
},
ip_detect_path=cluster_backend.ip_detect_path,
output=Output.LOG_AND_CAPTURE,
)
cluster.wait_for_dcos_ee(
superuser_username=superuser_username,
superuser_password=superuser_password,
)
# No error is raised with a successful command.
# We choose a test file which runs very quickly.
fast_test_file = 'test_marathon_authn_authz.py'
cluster.run_with_test_environment(
args=['pytest', '-vvv', '-s', '-x', fast_test_file],
env={
'DCOS_LOGIN_UNAME': superuser_username,
'DCOS_LOGIN_PW': superuser_password,
},
output=Output.LOG_AND_CAPTURE,
)
示例11: test_wait_for_dcos_ee
# 需要導入模塊: from passlib.hash import sha512_crypt [as 別名]
# 或者: from passlib.hash.sha512_crypt import hash [as 別名]
def test_wait_for_dcos_ee(
self,
cluster_backend: ClusterBackend,
enterprise_1_11_installer: Path,
license_key_contents: str,
) -> None:
"""
A cluster can start up with SSL disabled.
"""
superuser_username = str(uuid.uuid4())
superuser_password = str(uuid.uuid4())
config = {
'superuser_username': superuser_username,
'superuser_password_hash': sha512_crypt.hash(superuser_password),
'fault_domain_enabled': False,
'license_key_contents': license_key_contents,
'security': 'disabled',
}
with Cluster(
cluster_backend=cluster_backend,
agents=0,
public_agents=0,
) as cluster:
cluster.install_dcos_from_path(
dcos_installer=enterprise_1_11_installer,
dcos_config={
**cluster.base_config,
**config,
},
output=Output.LOG_AND_CAPTURE,
ip_detect_path=cluster_backend.ip_detect_path,
)
cluster.wait_for_dcos_ee(
superuser_username=superuser_username,
superuser_password=superuser_password,
)
# On 1.11 with security mode disabled, SSL is disabled.
any_master = next(iter(cluster.masters))
config_result = any_master.run(
args=['cat', '/opt/mesosphere/etc/bootstrap-config.json'],
)
config = json.loads(config_result.stdout.decode())
ssl_enabled = config['ssl_enabled']
assert not ssl_enabled