Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Benutzer: Ineluki / Datum: 19.12.2009 / Zeit: 14:36 */
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace login_check
- {
- class Program
- {
- public struct loginstruct {
- public string un;
- public string pw;
- public string pwsi;
- private string _pwsi2;
- public string pwsi2{
- get{
- return this._pwsi2;
- }
- set{
- if (value != pwsi) {
- throw new Exception ("Password does not match with Retyped Password.");
- }
- this._pwsi2 = value;
- }
- }
- public string _email;
- public string email{
- get{
- return this._email;
- }
- set{
- bool form=value.Contains("@") &&(value.Contains(".de") ||value.Contains(".com"));
- if (!form){
- throw new Exception ("Your Email adress is incorrect.");
- }
- this._email=value;
- }
- }
- }
- public static string decrypt(string a){
- char[] b=a.ToCharArray();
- for (int x=0;x<b.Length;++x){
- b[x]+=(char)2;
- }
- return new string(b);
- }
- public static void LoginOrSignup (){
- bool ls=false;
- bool fehler=false;
- do{
- Console.Write("{0}\n","Please choose:\t(0) Login, (1) Sign up");
- int e=Convert.ToInt32(Console.ReadLine());
- if (e==0){
- ls=true;
- fehler=true;
- }
- if (e==1){
- ls=false;
- fehler=true;
- }
- if (e!=0 &&e!=1){
- Console.Write("Choose only from the given options.\n");
- fehler=false;
- }
- } while(!fehler);
- if (ls) login(); else signup();
- }
- public static void login(){
- loginstruct lo=new loginstruct();
- using (StreamReader sr=new StreamReader("asd.txt")){
- string line;
- bool fehler=false;
- while ((line=sr.ReadLine())!=null&& !fehler){
- do{
- Console.Write("\n{0}\n{1}","LOGIN","Username or Email adress:");
- lo.un=Console.ReadLine();
- Console.Write("{0}","Password:");
- lo.pw=Console.ReadLine();
- bool UNcorrect=false;
- do{
- UNcorrect=line.Contains(lo.un);
- if (!UNcorrect){
- line=sr.ReadLine();
- }
- }while (!UNcorrect);
- bool PWcorrect=false;
- if (UNcorrect){
- PWcorrect=line.Contains(decrypt(lo.pw));
- }
- if (UNcorrect &&PWcorrect){
- Console.Write("Username matches with password. Access granted. Loading...");
- fehler=true;
- }
- else{
- Console.Write("Error: "+"Username and password do not match. "+"Try again.\n");
- fehler=false;
- }
- } while (!fehler);
- }
- }
- }
- public static void signup(){
- loginstruct si=new loginstruct();
- using (StreamWriter sw=File.AppendText("asd.txt")){
- Console.Write("\n{0}\n{1}","SIGNUP","Desired Username:");
- si.un=Console.ReadLine();
- bool fehler=false;
- do {
- try {
- Console.Write("{0}","Pick a Password:");
- si.pwsi=Console.ReadLine();
- Console.Write("{0}","Retype Password:");
- si.pwsi2=Console.ReadLine();
- fehler=false;
- }
- catch (Exception ex){
- fehler=true;
- Console.Write("Error: "+ex.Message+" Try again.\n");
- }
- } while(fehler);
- bool fehler2=false;
- do {
- try {
- Console.Write("{0}","Email adress:");
- si.email=(Console.ReadLine());
- fehler2=false;
- }
- catch (Exception ex){
- fehler2=true;
- Console.Write("Error: "+ex.Message+" Enter again.\n");
- }
- } while(fehler2);
- sw.WriteLine("{0},{1},{2}!",si.un,decrypt(si.pwsi),si.email);
- }
- login();
- }
- public static void Main(){
- LoginOrSignup();
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement