C#spring Music Player Login Interface programming

Source: Internet
Author: User

Spring Music Player, our team designed to start with a login interface, the user can register for the first time, enter the user name and password, click on the registration will enter the information saved to the register text file, if there is a user name, enter a user name and password, click Login, The program will compare the user name and password entered with the existing user information, if you find an exact match of the user name and password, then enter the music playback interface; if it does not match, the message box: User name or password error.

First create a Login interface window, add Button,label, and textbox, change the form background, such as.

The registration and Login buttons are then programmed for message response.

C # Programming content mainly involves the reading and writing of files, as well as judgment, relatively simple.

Here are some things to note:

Enter the user name and password in the textbox, first click the Register button, the program writes the characters in the textbox to the new Register.txt document, the user name and password line;

When registering, if the user name or password is empty, pop-up message box prompt please fill in the user name or password;

When registering, if the user name repeats, the user name is repeated, not written to the document;

When logged in, if the user name or password is empty, pop-up message box prompt please fill in the user name or password;

When logged in, if the user name or password is wrong, the pop-up message box prompts the user name or password error;

The default generated Register.txt on the desktop, after which the user name and password are written in the next two lines of the previously registered account.

The specific implementation code is as follows:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingSystem.IO;Ten  One namespaceSpring Music player A { -      Public Partial classLogin Interface: Form -     { the          PublicLogin Interface () -         { - InitializeComponent (); -         } +         //Register -         Private voidRegister_click (Objectsender, EventArgs e) +         { ABoolean flag =false;//Boolean variable at             stringPath =@"C:\Users\Administrator\Desktop\Register.txt"; -  -             //determine if the full user name and password are filled in -             if(string. Isnullorwhitespace (username. Text) | |string. Isnullorwhitespace (password. Text)) -             { -MessageBox.Show ("please fill in the user name or password"); in                 return; -             } to  +             if(! File.exists (PATH))//Create a document if it does not exist -             { the                 //Create a file to write to. *                 using(StreamWriter SW =file.createtext (path)) $                 {Panax Notoginseng                     //One line user name, one line password -Sw. WriteLine ( This. Username. Text); theSw. WriteLine ( This. Password. Text); +MessageBox.Show ("Registration Successful! "); A SW. Close (); the                 } +             } -             Else $             { $                 //determine if the user name is duplicated -StreamReader objreader =NewStreamReader ("C:/users/administrator/desktop/register.txt"); -                 stringsline =""; the                 inti =0; -                  while((sline = objReader.ReadLine ())! =NULL)Wuyi                 { thei++; -                     if( This. Username. Text = = Sline && convert.toint32 (i)%2==1) Wu                     { -MessageBox.Show ("This user name is already in use! "); AboutFlag =true; $                          Break; -                     } -                 } - objreader.close (); A  +                 if(Flag = =true) the                     return; -                 Else $                     //Keep Writing in an existing document the                     using(StreamWriter SW =file.appendtext (path)) the                     { theSw. WriteLine ( This. Username. Text); theSw. WriteLine ( This. Password. Text); -MessageBox.Show ("Registration Successful! "); in SW. Close (); the                     } the             } About         } the         //Login the         Private voidLaunch_click (Objectsender, EventArgs e) the         { +Boolean flag =false; -             stringUsername = This. Username. Text; the             stringPassword = This. Password. Text;Bayi             if(string. Isnullorwhitespace (username) | |string. Isnullorwhitespace (password)) the             { theMessageBox.Show ("please fill in the user name or password"); -                 return; -             } theStreamReader objreader =NewStreamReader ("C:/users/administrator/desktop/register.txt"); the             stringsline =""; the             inti =0; the             intn =0; -              while((sline = objReader.ReadLine ())! =NULL) the             { thei++; the                 if(Username = =sline && convert.toint32 (i)% 2 = = 1)//username is in odd line94n = i+1; the                 if(n = = i && password = =sline)//password in the next line of the corresponding user name the                 { theMessageBox.Show ("Login Successful! ");98Flag =true; About                      Break; -                 }101             } 102 objreader.close ();103             if(Flag = =false )104MessageBox.Show ("The user name or password is wrong! "); the         }106     }107}

The experiment is as follows:

Registering and writing content:

Duplicate user name when registering:

Login:

Password not entered at registration:

Password error at logon:

Note:

The login interface has not been linked with the playback interface, that is, registration or login does not jump to the playback interface;

User name and password input is not limited;

The meaning of registering a user name is to be ready to add songs in the playback interface to generate the song directory, corresponding to the user name, so that each account has its own playlist!

C#spring Music Player Login Interface programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.