ok so here is what my code does, when you click sign up it will then open a new form wherein you can create your account by putting a username and password, after that it will save your username and password to the debug folder inside bin folder. the saved account info is in a notepad file. Now my question is how do I make it something like when I login I will just have to type the username and password that I created for my account and the login form will detect it and allow login. I mean how do I get the information from the saved notepad to be recognized by my login form? help me pleasee. if you want the program itself I can email it to you right away just ask for it. regfdgfdgfdgfdgdfgdfgdfgdfgdf

Why are you using a txt file(not very safe) use a Database.
Tell me what have you done so far code wise.
You use StreamReader to read from a file

Edited 4 Years Ago by Michael27

@skatamatic

here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace LoginWithCreateUser
{
    public partial class AccountGenerator : Form
    {
        List<string> Accounts = new List<string>();

        public AccountGenerator()
        {
            InitializeComponent();
        }

        private void create_button_Click(object sender, EventArgs e)
        {
            string newAccount = textBox1.Text + ":" + textBox2.Text;
            Accounts.Add(newAccount);
            saveAccounts();
            MessageBox.Show("Account created");


        }

        private void LoadAccounts()
        {
            using (StreamReader SR = new StreamReader("Accounts.txt"))
            {
                while (SR.EndOfStream == false)
                {
                    Accounts.Add(SR.ReadLine());
                }
            }
        }

        private void saveAccounts()
        {
            using (StreamWriter SW = new StreamWriter("Accounts.txt"))
            {
                for (int i = 0; i < Accounts.Count; i++)
                {
                    SW.WriteLine(Accounts[i]);
                }
            }

        }

        private void AccountGenerator_Load(object sender, EventArgs e)
        {
            LoadAccounts();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }



    }
}

please give me the code to make my login form recognize all the username and password saved in the account.txt

You have to read txt file and compare your username and password from txtboxes to values in txt file.

Comments
please code it im confused ...

Yes, this is how it suppose to be done with the login checking. This is the correct way.

I dont know which file you use, and what is your data structure in it. So cant tell you more.
But I would suggest you something like (data strucure of txt file):

username;password

Semicolon is a delimiter between username and password. And you have to make sure of one thing when registering new user - DO NOT ALLOW to insert this delimiter in any case. And no matter which one it is.

Next you can read line by line and check login:

bool bValid = false;
using(StreamReader sr = new StreamReader("fileName.txt"))
{
    string line;
    while((line = sr.ReadLine()) != null)
    {
        string[] data = line.Split(';');
        if(data[0] == textBoxUsername.Text.Trim() &&
           data[1] == textBoxPassword.Text.Trim())
           {
                //login successful!!
                bValid = true;
                break;
           }
    }
}
if(bValid)
{
    //continue working, login was a success!!
}
else
{
    //show a message login was not successful!
}

Thisis it¨!

Edited 4 Years Ago by Mitja Bonca

YIKES! Storing passwords as plain text.

Here's a tip for you there, HASH them. When they create the account you hash the password and store the results. Then when they try to log in, you hash their password they have entered and see if it compares to the one in the file.

(If you wonder Hashing is an irreversable way to compare data. When you hash you take a collection of data, and store it in a string that is a set length depending on the type of hashing you use. As I said this can't be reversed, the only way it can be hacked is by someone who has created tables of data creating tons of hashes hoping to find one that matches those stored in a file, only then do they know the plain text, which can be very time consuming to do).

Also, SQLite my friend. It's a SQL database, but it's stored as a local file on your system. I use to do stuff like .txt files till I found this.

Here's a link, find the version that matches the right your specs (.NET and 32 or 64 bit)
http://www.sqlite.org/download.html

Edited 2 Years Ago by JOSheaIV

This article has been dead for over six months. Start a new discussion instead.