I'm taking a C# beginners course at my university this semester, and for my final project I'm trying to make a login and register for my "course database". I got the login working recently, but ever since I added the register form to the project the login stopped working and instead gave me errors. I have tried without avail to get login working again, but I have had no such luck. I was hoping you guys could help me out.
Below is what I've got so far.
--
This is the login portion. I use streamreader to read login information from text files in the debug folder of my visual c# project. If the login is successful, then the database form is displayed (which I have not shown here). If not, then invalid input is displayed.
--
namespace CourseDataFinal3
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private int userID;
private string password;
The error message will display when an exception is thrown. Since the name and password fields being blank does not throw an exception, the message will never display. Instead you should remove the Try/Catch block and instead do checking at the start of the method:
Second, you have chosen an odd design to store username and passwords of multiple registrants. The database strategy you have chosen is using a "flat file" (which is fine for these purposes), but you seem to be storing related fields in two different files. A better strategy would be to create a single file (logindata.txt) that hold pairs of usernames and passwords, seperated by a comma, one to a line (this is called "CSV"). That is with format.
(Note that your current strategy of using File.ReadToEnd(string) to read the entire contents into a single string variable is the source of at least one of your problems; your login checking subroutine does not seem to contemplate the possibility of multiple registrants).
And perform a loop to check to see if usernameTextBox.Text + "," + passTextBox.Text is contained in any element of string[] userpasscombos.
Aye?
Also please use [code] and [/code] tags around code to preserve formatting.
Last edited by BioPhysEngr; December 18th, 2011 at 04:50 PM.
Reason: typo
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks