mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-28 04:46:34 -04:00
Fixed user being served complexity prompts multiple times when password generation is attempted more than once
This commit is contained in:
@@ -74,19 +74,22 @@ def shm_gen(): # generates a random temporary folder for security and returns r
|
||||
|
||||
|
||||
def pass_gen():
|
||||
def _pass_gen_function(__complexity, __length):
|
||||
if __complexity.lower() == 's':
|
||||
__character_pool = string.ascii_letters + string.digits
|
||||
else:
|
||||
__character_pool = string.ascii_letters + string.digits + string.punctuation
|
||||
__gen = ''.join(random.SystemRandom().choice(__character_pool) for _ in range(__length))
|
||||
__min_special, __special = round(.2 * __length), 0
|
||||
for __character in __gen:
|
||||
if not __character.isalpha():
|
||||
__special += 1
|
||||
if __special < __min_special:
|
||||
__gen = _pass_gen_function(__complexity, __length)
|
||||
return __gen
|
||||
_length = int(input('How many characters should be in the password? '))
|
||||
_complexity = str(input('Should the password be simple (for compatibility) or complex (for security)? (s/C) '))
|
||||
if _complexity.lower() == 's':
|
||||
_complexity = string.ascii_letters + string.digits
|
||||
else:
|
||||
_complexity = string.ascii_letters + string.digits + string.punctuation
|
||||
_gen = ''.join(random.SystemRandom().choice(_complexity) for _ in range(_length))
|
||||
_min_special, _special = round(.2 * _length), 0
|
||||
for _character in _gen:
|
||||
if not _character.isalpha():
|
||||
_special += 1
|
||||
if _special < _min_special:
|
||||
_gen = pass_gen()
|
||||
_gen = _pass_gen_function(_complexity, _length)
|
||||
return _gen
|
||||
|
||||
|
||||
@@ -321,7 +324,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
||||
if Path(f"{path.expanduser('~')}{_folder[:-1]}").is_dir():
|
||||
pass
|
||||
else:
|
||||
print(f"\u001b[38;5;2m{_folder.replace('/.password-pasture/', '')[:-1]}/\u001b[0m does not exist locally, "
|
||||
print(f"\u001b[38;5;2m{_folder.replace('/.password-pasture/', '')[:-1]}/\u001b[0m does not exist locally, "
|
||||
f"creating...")
|
||||
Path(f"{path.expanduser('~')}{_folder[:-1]}").mkdir(0o700, parents=True, exist_ok=True)
|
||||
# set permissions before uploading
|
||||
@@ -624,7 +627,7 @@ if __name__ == "__main__":
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit(0)
|
||||
elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith('edit password')\
|
||||
elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith('edit password') \
|
||||
or argument.startswith('edit -p') or argument.startswith('edit url') or argument.startswith('edit -l') or \
|
||||
argument.startswith('edit note') or argument.startswith('edit -n'):
|
||||
try:
|
||||
@@ -638,8 +641,8 @@ if __name__ == "__main__":
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit(0)
|
||||
elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith('copy password')\
|
||||
or argument.startswith('copy -p') or argument.startswith('copy url') or argument.startswith('copy -l')\
|
||||
elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith('copy password') \
|
||||
or argument.startswith('copy -p') or argument.startswith('copy url') or argument.startswith('copy -l') \
|
||||
or argument.startswith('copy note') or argument.startswith('copy -n'):
|
||||
try:
|
||||
copy_data()
|
||||
@@ -661,10 +664,10 @@ if __name__ == "__main__":
|
||||
|
||||
# sync at end of program if any changes were made
|
||||
if argument != '' and argument != 'help' and argument != '--help' and argument != '-h' and argument != 'license' \
|
||||
and argument != 'add' and argument != 'sync' and argument != 'edit' and not argument.\
|
||||
startswith('copy username') and not argument.startswith('copy -u') and not argument.\
|
||||
startswith('copy password') and not argument.startswith('copy -p') and not argument.\
|
||||
startswith('copy url') and not argument.startswith('copy -l') and not argument.\
|
||||
and argument != 'add' and argument != 'sync' and argument != 'edit' and not argument. \
|
||||
startswith('copy username') and not argument.startswith('copy -u') and not argument. \
|
||||
startswith('copy password') and not argument.startswith('copy -p') and not argument. \
|
||||
startswith('copy url') and not argument.startswith('copy -l') and not argument. \
|
||||
startswith('copy note') and not argument.startswith('copy -n') and argument != 'copy' and argument \
|
||||
!= 'version' and argument != '-v' and error == 0 and argument.startswith('/') is False:
|
||||
sync()
|
||||
|
||||
Reference in New Issue
Block a user