003-password.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import sys
  2. import pathlib
  3. import asyncio
  4. test_file = pathlib.Path(__file__)
  5. project = test_file.parent.parent
  6. sys.path.append(str(project))
  7. import server_source as source
  8. from test import test
  9. async def main():
  10. print("Generating password...")
  11. password = await source.password.from_plain_text("Sample")
  12. print(repr(password))
  13. print("Lenght: " + str(len(password.result())))
  14. print()
  15. print("Checking password...")
  16. test(await password.compare("Sample"), True)
  17. test(await password.compare("Samples"), False)
  18. print()
  19. print("Generating other password...")
  20. second_password = await source.password.from_plain_text("other")
  21. print(repr(second_password))
  22. print()
  23. print("Checking password...")
  24. test(await second_password.compare("other"), True)
  25. test(await second_password.compare("other_fail"), False)
  26. print()
  27. print("Generating other password with same content other salt...")
  28. variant = await source.password.from_plain_text("Sample")
  29. print(repr(variant))
  30. print()
  31. print("Checing it...")
  32. test(await variant.compare("Sample"), True)
  33. test(await password.compare("Sample"), True)
  34. print()
  35. print("Regenerating password from hash...")
  36. restore = await source.password.from_hash(password.result())
  37. print("Old: " + repr(password))
  38. print("Restored: " + repr(restore))
  39. print()
  40. print("Validating...")
  41. test(await restore.compare("Sample"), True)
  42. test(await restore.compare("Sampled"), False)
  43. print()
  44. asyncio.run(main())