Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace LoginTest {
- public partial class Form1 : Form {
- String username = "";
- String password = "";
- int counter = 0;
- string line;
- public Form1() {
- InitializeComponent();
- }
- private void ExitButton_Click(object sender, EventArgs e) {
- this.Close();
- }
- private void loginButton_Click(object sender, EventArgs e) {
- // Read the file and display it line by line.
- System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\Asif\Documents\Visual Studio 2015\Projects\LoginTest\file.txt");
- while ((line = file.ReadLine()) != null) {
- if (counter == 0) username = line;
- if (counter == 1) password = line;
- counter++;
- }
- //Check if user made an account
- if (username.Length == 0 || password.Length == 0) {
- MessageBox.Show("Please enter your username and password to continue! ");
- return;
- }
- //Check username and password
- if (username == UsernameTextBox.Text && password == PasswordTextBox.Text) {
- MessageBox.Show("You have successfully logged in!");
- }
- else {
- MessageBox.Show("Incorrect username or password");
- }
- }
- private void RegisterButton_Click(object sender, EventArgs e) {
- string[] userInfo = { UsernameTextBox.Text, PasswordTextBox.Text };
- if (UsernameTextBox.TextLength == 0 || PasswordTextBox.TextLength == 0) {
- MessageBox.Show("Please enter a desired username and password in order to continue.");
- return;
- }
- /*
- username = UsernameTextBox.Text;
- password = PasswordTextBox.Text;
- */
- System.IO.File.WriteAllLines(@"C:\Users\Asif\Documents\Visual Studio 2015\Projects\LoginTest\file.txt", userInfo);
- UsernameTextBox.Text = "";
- PasswordTextBox.Text = "";
- loginButton.Enabled = true;
- MessageBox.Show("Account has been created! Log in again to continue!");
- }
- private void Form1_Load(object sender, EventArgs e) {
- if (File.Exists(@"C:\Users\Asif\Documents\Visual Studio 2015\Projects\LoginTest\file.txt")) {
- if (new FileInfo(@"C:\Users\Asif\Documents\Visual Studio 2015\Projects\LoginTest\file.txt").Length != 0) {
- loginButton.Enabled = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement