Advertisement
Guest User

Untitled

a guest
May 5th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.76 KB | None | 0 0
  1.  /* Benutzer: Ineluki / Datum: 19.12.2009 / Zeit: 14:36 */
  2. using System;
  3. using System.IO;
  4. using System.Collections.Generic;
  5.  
  6. namespace login_check
  7. {
  8.     class Program
  9.     {
  10.         public struct loginstruct {
  11.             public string un;
  12.             public string pw;
  13.             public string pwsi;
  14.             private string _pwsi2;
  15.             public string pwsi2{
  16.                 get{
  17.                     return this._pwsi2;
  18.                 }
  19.                 set{
  20.                     if (value != pwsi) {
  21.                         throw new Exception ("Password does not match with Retyped Password.");
  22.                     }
  23.                     this._pwsi2 = value;
  24.                 }
  25.                
  26.             }
  27.             public string _email;
  28.             public string email{
  29.                 get{
  30.                     return this._email;
  31.                 }
  32.                 set{
  33.                     bool form=value.Contains("@") &&(value.Contains(".de") ||value.Contains(".com"));
  34.                     if (!form){
  35.                         throw new Exception ("Your Email adress is incorrect.");
  36.                         }
  37.                     this._email=value;
  38.                 }
  39.             }
  40.         }
  41.        
  42.         public static string decrypt(string a){
  43.             char[] b=a.ToCharArray();
  44.             for (int x=0;x<b.Length;++x){
  45.                 b[x]+=(char)2;
  46.             }
  47.             return new string(b);
  48.         }
  49.        
  50.         public static void LoginOrSignup (){
  51.             bool ls=false;
  52.             bool fehler=false;
  53.             do{
  54.                 Console.Write("{0}\n","Please choose:\t(0) Login, (1) Sign up");
  55.                 int e=Convert.ToInt32(Console.ReadLine());
  56.                 if (e==0){
  57.                     ls=true;
  58.                     fehler=true;
  59.                 }
  60.                 if (e==1){
  61.                     ls=false;
  62.                     fehler=true;
  63.                 }
  64.                 if (e!=0 &&e!=1){
  65.                     Console.Write("Choose only from the given options.\n");
  66.                     fehler=false;
  67.                 }
  68.             } while(!fehler);
  69.             if (ls) login(); else signup();
  70.         }
  71.  
  72.         public static void login(){
  73.             loginstruct lo=new loginstruct();
  74.            
  75.             using (StreamReader sr=new StreamReader("asd.txt")){
  76.                 string line;
  77.                 bool fehler=false;
  78.                 while ((line=sr.ReadLine())!=null&& !fehler){
  79.                     do{
  80.                         Console.Write("\n{0}\n{1}","LOGIN","Username or Email adress:");
  81.                         lo.un=Console.ReadLine();
  82.                         Console.Write("{0}","Password:");
  83.                         lo.pw=Console.ReadLine();
  84.                         bool UNcorrect=false;
  85.                             do{
  86.                             UNcorrect=line.Contains(lo.un);
  87.                             if (!UNcorrect){
  88.                                 line=sr.ReadLine();
  89.                             }
  90.                             }while (!UNcorrect);
  91.                         bool PWcorrect=false;
  92.                         if (UNcorrect){
  93.                             PWcorrect=line.Contains(decrypt(lo.pw));
  94.                         }
  95.                         if (UNcorrect &&PWcorrect){
  96.                             Console.Write("Username matches with password. Access granted. Loading...");
  97.                             fehler=true;
  98.                         }
  99.                         else{
  100.                             Console.Write("Error: "+"Username and password do not match. "+"Try again.\n");
  101.                             fehler=false;
  102.                         }
  103.                     } while (!fehler);     
  104.                 }
  105.             }
  106.         }
  107.  
  108.         public static void signup(){
  109.             loginstruct si=new loginstruct();
  110.             using (StreamWriter sw=File.AppendText("asd.txt")){
  111.                     Console.Write("\n{0}\n{1}","SIGNUP","Desired Username:");
  112.                     si.un=Console.ReadLine();
  113.                     bool fehler=false;
  114.                     do {
  115.                         try {
  116.                             Console.Write("{0}","Pick a Password:");
  117.                             si.pwsi=Console.ReadLine();
  118.                             Console.Write("{0}","Retype Password:");
  119.                             si.pwsi2=Console.ReadLine();
  120.                             fehler=false;
  121.                         }
  122.                         catch (Exception ex){
  123.                             fehler=true;
  124.                             Console.Write("Error: "+ex.Message+" Try again.\n");
  125.                         }
  126.                     } while(fehler);
  127.              
  128.                     bool fehler2=false;
  129.                     do {
  130.                         try {
  131.                             Console.Write("{0}","Email adress:");
  132.                             si.email=(Console.ReadLine());
  133.                             fehler2=false;
  134.                         }
  135.                         catch (Exception ex){
  136.                             fehler2=true;
  137.                             Console.Write("Error: "+ex.Message+" Enter again.\n");
  138.                         }
  139.                     } while(fehler2);
  140.                     sw.WriteLine("{0},{1},{2}!",si.un,decrypt(si.pwsi),si.email);
  141.             }
  142.             login();
  143.         }
  144.  
  145.         public static void Main(){
  146.             LoginOrSignup();
  147.             Console.ReadKey(true);
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement