Skip to content

Commit b54010c

Browse files
author
CosmoSt4r
committed
First testing version
0 parents  commit b54010c

File tree

7 files changed

+129
-0
lines changed

7 files changed

+129
-0
lines changed

LICENSE.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
MIT License
2+
Copyright (c) 2018 YOUR NAME
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
The above copyright notice and this permission notice shall be included in all
10+
copies or substantial portions of the Software.
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

README.md

Whitespace-only changes.

pypasswords/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .main import hash_it

pypasswords/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sault_dictionary = '1234567890\
2+
qwertyuiopasdfghjklzxcvbnm\
3+
QWERTYUIOPASDFGHJKLZXCVBNM\
4+
!@#$%^&*()-=_+|,./<>?;:"[]{}'

pypasswords/main.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import hashlib
2+
from random import choice
3+
from .config import sault_dictionary
4+
from zxcvbn import zxcvbn
5+
from math import log
6+
7+
8+
def hash_it(password, hash_type='sha256', saulting=False,
9+
static_sault='', sault_length=6, local_parameter=''):
10+
11+
def hash_password(word, hashing_type):
12+
13+
# hashing password
14+
try:
15+
hashed_password = hashlib.new(hashing_type)
16+
except ValueError:
17+
raise ValueError(f'unsupported hash type {hashing_type}. Try using sha256, sha384, sha512')
18+
19+
hashed_password.update(word.encode())
20+
word = hashed_password.hexdigest()
21+
return word
22+
23+
def sault_password(word, static, length):
24+
25+
# adding sault to the password
26+
if not static:
27+
# if static_sault isn't specified, generate the sault
28+
sault = ''
29+
for _ in range(length):
30+
sault += choice(sault_dictionary)
31+
return word + sault
32+
else:
33+
# using static_sault
34+
sault = static
35+
return word + sault
36+
37+
def add_local_parameter(word, parameter):
38+
39+
# adding locale_parameter
40+
return word + parameter
41+
42+
# main function to hash the password
43+
if saulting:
44+
password = sault_password(password, static_sault, sault_length)
45+
46+
if local_parameter:
47+
password = add_local_parameter(password, local_parameter)
48+
49+
password = hash_password(password, hash_type)
50+
return password
51+
52+
53+
def check_it(password, check_type='strength', stop_chars=''):
54+
55+
if check_type == 'strength':
56+
result = zxcvbn(password)['crack_times_seconds']['online_no_throttling_10_per_second']
57+
result = int(log(result, 10))
58+
59+
elif check_type == 'valid':
60+
for c in password:
61+
# checking every char in password
62+
if c in stop_chars:
63+
# if stop_char in password then it is invalid
64+
result = False
65+
break
66+
else:
67+
# if there is no stop_chars in password then it is valid
68+
result = True
69+
else:
70+
# unknown check_type
71+
raise ValueError(f'unsupported check type {check_type}. Try using strength, valid.')
72+
73+
return result

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

setup.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from distutils.core import setup
2+
setup(
3+
name = 'pypasswords',
4+
packages = ['pypasswords'],
5+
version = '0.1',
6+
license='MIT',
7+
description = 'Working with passwords made simple',
8+
author = 'CosmoStar',
9+
author_email = 'JustCosmos@yandex.ru',
10+
url = 'https://github.com/CosmoSt4r/pypasswords',
11+
download_url = 'https://github.com/CosmoSt4r/pypasswords/archive/v_01.tar.gz',
12+
keywords = ['password', 'passwords', 'check', 'hash', 'simple'],
13+
install_requires=[
14+
'hashlib',
15+
'zxcvbn',
16+
],
17+
classifiers=[
18+
19+
'Development Status :: 3 - Alpha',
20+
21+
'Intended Audience :: Developers',
22+
'Topic :: Software Development :: Build Tools',
23+
24+
'License :: OSI Approved :: MIT License',
25+
26+
'Programming Language :: Python :: 3',
27+
'Programming Language :: Python :: 3.4',
28+
'Programming Language :: Python :: 3.5',
29+
'Programming Language :: Python :: 3.6',
30+
'Programming Language :: Python :: 3.7',
31+
],
32+
)

0 commit comments

Comments
 (0)