Advertisement
Guest User

Untitled

a guest
Feb 1st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import re
  2.  
  3. # This is the class that reads in the user's credentials:
  4. class InputReader():
  5.   def __init__(self):
  6.     self.username = ""
  7.     self.password = ""
  8.     self.credentials = ""
  9.  
  10.   def readInput(self):
  11.     self.username = raw_input("Username: ")
  12.     self.password = raw_input("Password: ")
  13.     self.credentials = self.username + ", " + self.password
  14.  
  15.   def getCredentials(self):
  16.     return self.credentials
  17.  
  18. class CredentialWriter():
  19.   def __init__(self, line = ""):
  20.     self.line = line
  21.  
  22.   def validCredentials(self):
  23.     ### Purpose: Determine whether or not the credentials (username + password) are valid.
  24.     if re.search("[%^&\d]", self.line) == None:
  25.       return True
  26.     else:
  27.       return False
  28.  
  29.   def writeToCorrectFile(self):
  30.     ### Purpose: Write the credentials to one of two files.
  31.     if self.validCredentials():
  32.       ### ^ We don't have to pass in line as an argument anymore.
  33.       file = open("human_login.csv","a")
  34.       file.write(self.line + "\n")
  35.       file.close()
  36.     else:
  37.       file = open("bot_login.csv","a")
  38.       file.write(self.line + "\n")
  39.       file.close()
  40.  
  41. # Create a new InputReader named ir.
  42. ir = InputReader()
  43.  
  44. # Run the readInput function to get the user's credentials.
  45. ir.readInput()
  46.  
  47. # Print out the username and password separated by a comma.
  48. print ir.getCredentials()
  49.  
  50. cw = CredentialWriter(ir.getCredentials())
  51. ### ^ ir.getCredentials is passed in here now because of __init__
  52. cw.writeToCorrectFile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement