locked
storing input of both letters and numbers (for example a password) RRS feed

  • Question

  • Pleasant greetings. i would like to get some assistant. i am writing some codes in C# console application, practicing. i would like to ask the user to choose a password and store that password so i can call the variable it was stored in to verify a login. How do i go about doing that. Bare in mind that the password could be letters or numbers or a mixture of both.your assistant would be appreciated.
    Thursday, April 16, 2015 9:53 PM

Answers

All replies

  • Hi

    I guess you are going simply go like this:

    string password = Console.ReadLine();

    or 

    var password = Console.ReadLine();


    Aram Koukia | Blog: koukia.ca | Twitter: @aramkoukia

    Thursday, April 16, 2015 10:03 PM
  • Hi Ricky,

    have a look here:
    Building Console Applications in the .NET Framework

    It says it contains a link to samples.


    Armin

    • Marked as answer by Caillen Thursday, April 23, 2015 8:49 AM
    Thursday, April 16, 2015 10:05 PM
  • What code do you have so far?  Use copy and paste to put the code you have so far in a code editing block.  (Use the second last button, the one which has <> on it to make a code editing block).

    Please don't type your code in, make sure you use copy and paste.


    Paul Linton

    Thursday, April 16, 2015 10:42 PM
  • Hello ,

    if you only want to store and call a string(letters and numbers) without security requirement, you can store the password string in a file and read it from the file when you need it.
    See [1] to learn more about reading and writing files in C#.

    [1] http://csharp.net-tutorials.com/file-handling/reading-and-writing/

    Regards,
    Bo Liu
    Developer-Hotline for MSDN Online Germany

    Disclaimer:
    Please take into consideration, that further inquiries cannot or will be answered with delay.
    For further information please contact us per telephone through the MSDN-Entwickler-Hotline: http://www.msdn-online.de/Hotline
    MSDN-Entwickler-Hotline: Fast and professional help for software developers free of charge!

    For this post by the MSDN-Entwickler-Hotline the following terms and conditions apply: Trademarks, Privacy as well as the separate terms of use for the MSDN-Entwickler-Hotline .

    • Proposed as answer by Kristin Xie Monday, April 20, 2015 3:13 AM
    • Marked as answer by Caillen Thursday, April 23, 2015 8:49 AM
    Friday, April 17, 2015 12:14 PM
  • Hi ricky,

    I assume you put username and password in a txt file.

    Then you have to read the text file using ReadLine() untill the number entered by the user is matched. If the number matches, read the password, if that matches do whatever, if not display error message. Like the code as below should help.

    string number = "";
    string password = "";
    
    using (StreamReader sr = File.OpenText(@"c:\textfile.txt"))
                {
                    String input;
                    while ((input = sr.ReadLine()) != null)
                    {
                        string[] line = input.Split(',');
                        username = line[0];
                        password = line[1];
                        if (yourUsername == username)
                        {
                             if (yourPassword == password)
                             {
                                  // Username & Password exist
                             }
                             else
                             {
                                  // Username & Password not found
                             }
                        }
                    }
                }

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 20, 2015 3:21 AM