0

I have two .py scripts and I want from main script to edit script where the password is stored. Here is the script with password:

    import getpass, os
    def log_in():
        Username = "username"
        Password = "password"
        getUsername = input("Username:")
        while getUsername != Username:
            print("Wrong username")
            getUsername = input("Username:")
        x = 0
        while x < 5:
            getPass = getpass.getpass("Password:")
            if getPass != Password:
                print("Password is invalid")
                x = x + 1
            else:
                print("Welcome back sir\n")
                x = 10

So if I want to let user change Password with their input but is it possible and if it is, how?

Raptr3x
  • 13
  • 4
  • Might I suggest storing and reading the username and password from a file instead of having them be part of the source code? – stelioslogothetis May 13 '17 at 23:34
  • What do you mean by file, what kind of file? Do you mean like .txt or? – Raptr3x May 13 '17 at 23:41
  • In a real scenario where you would have a login/logout system you would use an SQL database. For your purposes you can simply read the data out of a `txt`. – stelioslogothetis May 13 '17 at 23:42
  • Yes, I see, and I can change txt file through python so that solves my question. Thank you very much! – Raptr3x May 13 '17 at 23:51
  • This isn't an answer to your question per-se, which is why I didn't post it as an answer. Still, glad I could help. – stelioslogothetis May 13 '17 at 23:52
  • 1
    @Sty I hope you're not suggesting to put the password plainly into the file... If this is for an actual application, there needs to at least be a salt and hashing implementation before writing to file, or the user's credentials are easily compromised.. – the_constant May 14 '17 at 00:00
  • 1
    It's _possible_ for a Python script to edit itself, but it's rarely a good idea. – PM 2Ring May 14 '17 at 00:33
  • see: http://stackoverflow.com/questions/7573599/change-python-source-while-running/7575998#7575998 for info on the byteplay module, which will allow you to accomplish what you want -- as others have noted, this is a terrible idea, but if you are just having fun, have at it : ) – pyInTheSky May 14 '17 at 01:26
  • Yes, I'm doing the project just for fun and I'm learning new stuff on the way so I'l try multiply ways – Raptr3x May 14 '17 at 12:36

0 Answers0