Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import socket
  2. import json
  3. import re
  4. import stat
  5. from hashlib import sha256
  6. import os
  7.  
  8.  
  9.  
  10. Serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11. Serveur.bind(("localhost", 15556))
  12. ParentDirectoryPath = os.path.dirname(__file__)
  13.  
  14. print (" Le serveur ecoute desormait sur le port : 15556")
  15.  
  16. while True:
  17. Serveur.listen(5)
  18. Client, Address = Serveur.accept()
  19. print " Le client : {} est maintenant connecte".format(Address)
  20.  
  21. data = Client.recv(1024)
  22. data = json.loads(data.decode())
  23. username = data.get("username")
  24. password = data.get("password")
  25.  
  26. if(len(password) >= 6 or len(password) <= 12):
  27. pattern = re.compile('^(?=.*[0-9]$)(?=.*[a-zA-Z])')
  28.  
  29. if(pattern.search(password)):
  30. print(password)
  31. hashedPwd = sha256(password.encode()).hexdigest()
  32.  
  33. if not os.path.exists(os.path.join(ParentDirectoryPath, username)):
  34. os.mkdir(os.path.join(ParentDirectoryPath, username))
  35.  
  36.  
  37. file.open(os.path.join(ParentDirectoryPath, username, "config.txt"), "w+")
  38. file.write(hashedPwd)
  39. file.close()
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. print "Fermeture du serveur"
  50. Client.close()
  51. Serveur.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement