username and password program using python 3.4












0















The text file is displayed like this:



apple,crumble



Where apple is the username and crumble is password, separated by the comma.



I need a password and username system to make sure the user is authorised. so far I've done this:



username = input("Please enter your name. ")
print("Your username has been created and is", username)
password = input("Now please create a password. ")

file = open("Login.txt","a")
file.write (username)
file.write (",")
file.write (password)
file.write("n")
file.close()


It saves the user username and password in a text file.
So how do I create a login system that checks for the username and the password from the text file line by line?



For example if a user enters a password and username located on line 7, the program needs to check all previous lines until it finds the input that the user has entered.




I can only use python, no other programs such as Pandas or CMD.




Thanks










share|improve this question




















  • 1





    What have you tried? What specifically do you need help with? Do you know how to read a file?

    – Carcigenicate
    Nov 15 '18 at 14:44






  • 1





    "i can only use python, no other programs such as pandas...". Pandas is a module in Python, not a new language or a program.

    – Austin
    Nov 15 '18 at 14:46











  • Hint: 1. declare a variable loginok=False 2. read the file one line at a time 3. for each line, strip the newline and split on comma (,) 4. first field is a username and second a password 5. if both match, set loginok to True and exit from loop Then after the loop, loginok tells you whether login was successful.

    – Serge Ballesta
    Nov 15 '18 at 14:57











  • The code to create to the password file is mostly redundant to the textual description and is no substitute for code attemtping to solve the query problem.

    – guidot
    Nov 15 '18 at 15:01
















0















The text file is displayed like this:



apple,crumble



Where apple is the username and crumble is password, separated by the comma.



I need a password and username system to make sure the user is authorised. so far I've done this:



username = input("Please enter your name. ")
print("Your username has been created and is", username)
password = input("Now please create a password. ")

file = open("Login.txt","a")
file.write (username)
file.write (",")
file.write (password)
file.write("n")
file.close()


It saves the user username and password in a text file.
So how do I create a login system that checks for the username and the password from the text file line by line?



For example if a user enters a password and username located on line 7, the program needs to check all previous lines until it finds the input that the user has entered.




I can only use python, no other programs such as Pandas or CMD.




Thanks










share|improve this question




















  • 1





    What have you tried? What specifically do you need help with? Do you know how to read a file?

    – Carcigenicate
    Nov 15 '18 at 14:44






  • 1





    "i can only use python, no other programs such as pandas...". Pandas is a module in Python, not a new language or a program.

    – Austin
    Nov 15 '18 at 14:46











  • Hint: 1. declare a variable loginok=False 2. read the file one line at a time 3. for each line, strip the newline and split on comma (,) 4. first field is a username and second a password 5. if both match, set loginok to True and exit from loop Then after the loop, loginok tells you whether login was successful.

    – Serge Ballesta
    Nov 15 '18 at 14:57











  • The code to create to the password file is mostly redundant to the textual description and is no substitute for code attemtping to solve the query problem.

    – guidot
    Nov 15 '18 at 15:01














0












0








0








The text file is displayed like this:



apple,crumble



Where apple is the username and crumble is password, separated by the comma.



I need a password and username system to make sure the user is authorised. so far I've done this:



username = input("Please enter your name. ")
print("Your username has been created and is", username)
password = input("Now please create a password. ")

file = open("Login.txt","a")
file.write (username)
file.write (",")
file.write (password)
file.write("n")
file.close()


It saves the user username and password in a text file.
So how do I create a login system that checks for the username and the password from the text file line by line?



For example if a user enters a password and username located on line 7, the program needs to check all previous lines until it finds the input that the user has entered.




I can only use python, no other programs such as Pandas or CMD.




Thanks










share|improve this question
















The text file is displayed like this:



apple,crumble



Where apple is the username and crumble is password, separated by the comma.



I need a password and username system to make sure the user is authorised. so far I've done this:



username = input("Please enter your name. ")
print("Your username has been created and is", username)
password = input("Now please create a password. ")

file = open("Login.txt","a")
file.write (username)
file.write (",")
file.write (password)
file.write("n")
file.close()


It saves the user username and password in a text file.
So how do I create a login system that checks for the username and the password from the text file line by line?



For example if a user enters a password and username located on line 7, the program needs to check all previous lines until it finds the input that the user has entered.




I can only use python, no other programs such as Pandas or CMD.




Thanks







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 15:24









kit

1,1063817




1,1063817










asked Nov 15 '18 at 14:40









xxMagnumxxMagnum

116




116








  • 1





    What have you tried? What specifically do you need help with? Do you know how to read a file?

    – Carcigenicate
    Nov 15 '18 at 14:44






  • 1





    "i can only use python, no other programs such as pandas...". Pandas is a module in Python, not a new language or a program.

    – Austin
    Nov 15 '18 at 14:46











  • Hint: 1. declare a variable loginok=False 2. read the file one line at a time 3. for each line, strip the newline and split on comma (,) 4. first field is a username and second a password 5. if both match, set loginok to True and exit from loop Then after the loop, loginok tells you whether login was successful.

    – Serge Ballesta
    Nov 15 '18 at 14:57











  • The code to create to the password file is mostly redundant to the textual description and is no substitute for code attemtping to solve the query problem.

    – guidot
    Nov 15 '18 at 15:01














  • 1





    What have you tried? What specifically do you need help with? Do you know how to read a file?

    – Carcigenicate
    Nov 15 '18 at 14:44






  • 1





    "i can only use python, no other programs such as pandas...". Pandas is a module in Python, not a new language or a program.

    – Austin
    Nov 15 '18 at 14:46











  • Hint: 1. declare a variable loginok=False 2. read the file one line at a time 3. for each line, strip the newline and split on comma (,) 4. first field is a username and second a password 5. if both match, set loginok to True and exit from loop Then after the loop, loginok tells you whether login was successful.

    – Serge Ballesta
    Nov 15 '18 at 14:57











  • The code to create to the password file is mostly redundant to the textual description and is no substitute for code attemtping to solve the query problem.

    – guidot
    Nov 15 '18 at 15:01








1




1





What have you tried? What specifically do you need help with? Do you know how to read a file?

– Carcigenicate
Nov 15 '18 at 14:44





What have you tried? What specifically do you need help with? Do you know how to read a file?

– Carcigenicate
Nov 15 '18 at 14:44




1




1





"i can only use python, no other programs such as pandas...". Pandas is a module in Python, not a new language or a program.

– Austin
Nov 15 '18 at 14:46





"i can only use python, no other programs such as pandas...". Pandas is a module in Python, not a new language or a program.

– Austin
Nov 15 '18 at 14:46













Hint: 1. declare a variable loginok=False 2. read the file one line at a time 3. for each line, strip the newline and split on comma (,) 4. first field is a username and second a password 5. if both match, set loginok to True and exit from loop Then after the loop, loginok tells you whether login was successful.

– Serge Ballesta
Nov 15 '18 at 14:57





Hint: 1. declare a variable loginok=False 2. read the file one line at a time 3. for each line, strip the newline and split on comma (,) 4. first field is a username and second a password 5. if both match, set loginok to True and exit from loop Then after the loop, loginok tells you whether login was successful.

– Serge Ballesta
Nov 15 '18 at 14:57













The code to create to the password file is mostly redundant to the textual description and is no substitute for code attemtping to solve the query problem.

– guidot
Nov 15 '18 at 15:01





The code to create to the password file is mostly redundant to the textual description and is no substitute for code attemtping to solve the query problem.

– guidot
Nov 15 '18 at 15:01












1 Answer
1






active

oldest

votes


















1














You can create dictionary first from that file then you can easily check username exsits then match the password as well. In here u need unique usernames(login system need it)



dict = {}
with open("Login.txt") as f:
for line in f:
(userName, password) = line.split(',')
dict[userName] = password


Then check if user name exists here. Then check password as well like below



if enteredName in dict:
if dict[enteredName] == enteredPassword:
print("login success")
eles:
print("wrong password")
else:
print("login failed")





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321868%2fusername-and-password-program-using-python-3-4%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can create dictionary first from that file then you can easily check username exsits then match the password as well. In here u need unique usernames(login system need it)



    dict = {}
    with open("Login.txt") as f:
    for line in f:
    (userName, password) = line.split(',')
    dict[userName] = password


    Then check if user name exists here. Then check password as well like below



    if enteredName in dict:
    if dict[enteredName] == enteredPassword:
    print("login success")
    eles:
    print("wrong password")
    else:
    print("login failed")





    share|improve this answer






























      1














      You can create dictionary first from that file then you can easily check username exsits then match the password as well. In here u need unique usernames(login system need it)



      dict = {}
      with open("Login.txt") as f:
      for line in f:
      (userName, password) = line.split(',')
      dict[userName] = password


      Then check if user name exists here. Then check password as well like below



      if enteredName in dict:
      if dict[enteredName] == enteredPassword:
      print("login success")
      eles:
      print("wrong password")
      else:
      print("login failed")





      share|improve this answer




























        1












        1








        1







        You can create dictionary first from that file then you can easily check username exsits then match the password as well. In here u need unique usernames(login system need it)



        dict = {}
        with open("Login.txt") as f:
        for line in f:
        (userName, password) = line.split(',')
        dict[userName] = password


        Then check if user name exists here. Then check password as well like below



        if enteredName in dict:
        if dict[enteredName] == enteredPassword:
        print("login success")
        eles:
        print("wrong password")
        else:
        print("login failed")





        share|improve this answer















        You can create dictionary first from that file then you can easily check username exsits then match the password as well. In here u need unique usernames(login system need it)



        dict = {}
        with open("Login.txt") as f:
        for line in f:
        (userName, password) = line.split(',')
        dict[userName] = password


        Then check if user name exists here. Then check password as well like below



        if enteredName in dict:
        if dict[enteredName] == enteredPassword:
        print("login success")
        eles:
        print("wrong password")
        else:
        print("login failed")






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 14:53

























        answered Nov 15 '18 at 14:48









        LuceferLucefer

        1,2361514




        1,2361514
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321868%2fusername-and-password-program-using-python-3-4%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues