Advertisement
Guest User

Untitled

a guest
Nov 8th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace Shell
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         bool insystem, error;
  17.         string login, password, state, access;
  18.         string[] rights;
  19.         string[][] tabrights = new string [10][];
  20.         string[] a;
  21.         int user, cursor;
  22.         int x, t;
  23.  
  24.         public void verify()
  25.         {
  26.             errorlabel.Visible = false;
  27.             textBox1.Visible = true;
  28.             button1.Visible = true;
  29.             label1.Visible = true;
  30.             x = (new Random()).Next(10);
  31.             label1.Text = x.ToString();
  32.         }
  33.  
  34.         public void show()
  35.         {
  36.  
  37.         }
  38.  
  39.         public Form1()
  40.         {
  41.             InitializeComponent();
  42.         }
  43.  
  44.         private void Form1_Load(object sender, EventArgs e)
  45.         {
  46.             state = "unsigned";
  47.  
  48.            
  49.             a = Directory.GetDirectories(@"D:\TZI");
  50.             for (int i = 0; i < a.Length; i++)
  51.             {
  52.                 a[i] = a[i].Substring(7);
  53.             }
  54.             rights = File.ReadAllLines(@"D:\TZI\S\users.txt");
  55.             for (int i=0 ; i< rights.Length ; i++)
  56.             {
  57.                 tabrights[i] = rights[i].Split(' ');  
  58.             }
  59.            
  60.         }
  61.        
  62.  
  63.         private void textBox2_TextChanged(object sender, EventArgs e)
  64.         {
  65.  
  66.         }
  67.  
  68.         private void button1_Click(object sender, EventArgs e)
  69.         {
  70.             login = Loginfield.Text;
  71.             password = Passwordfield.Text;
  72.             for (int i=0; i<rights.Length; i++)
  73.             {
  74.                 if (tabrights[i][0] == login)
  75.                 {
  76.                     if (tabrights[i][1] == password)
  77.                     {
  78.                         /*state = login;
  79.                         Statelabel.Text = state; */
  80.                         error = false;
  81.                         errorlabel.Visible = error;
  82.                         textBox1.Visible = true;
  83.                         button1.Visible = true;
  84.                         label1.Visible = true;
  85.                         x = (new Random()).Next(10);
  86.                         label1.Text = x.ToString();
  87.                         user = i;
  88.                         break;
  89.                     }
  90.                     else
  91.                     {
  92.                         errorlabel.Text = "Wrong password";
  93.                         error = true;
  94.                         errorlabel.Visible = error;
  95.                         Loginfield.Text = null;
  96.                         Passwordfield.Text = null;
  97.                         //func();
  98.                         break;
  99.                     }
  100.                    
  101.                 }
  102.                 else
  103.                 {
  104.                     errorlabel.Text = "Login not found";
  105.                     error = true;
  106.                     errorlabel.Visible = error;
  107.                     Loginfield.Text = null;
  108.                     Passwordfield.Text = null;
  109.                 }
  110.             }
  111.  
  112.             loginbutton.Visible = (state == "unsigned");
  113.             Loginlabel.Visible = (state == "unsigned");
  114.             Loginfield.Visible = (state == "unsigned");
  115.             Passwordfield.Visible = (state == "unsigned");
  116.             Passwordlabel.Visible = (state == "unsigned");
  117.             logoutbutton.Visible = !(state == "unsigned");
  118.         }
  119.  
  120.         private void button2_Click(object sender, EventArgs e)
  121.         {
  122.             state = "unsigned";
  123.             Loginfield.Text = null;
  124.             Passwordfield.Text = null;
  125.             Statelabel.Text = state;
  126.             folderlist.Items.Clear();
  127.             loginbutton.Visible = (state == "unsigned");
  128.             Loginlabel.Visible = (state == "unsigned");
  129.             Loginfield.Visible = (state == "unsigned");
  130.             Passwordfield.Visible = (state == "unsigned");
  131.             Passwordlabel.Visible = (state == "unsigned");
  132.             logoutbutton.Visible = !(state == "unsigned");
  133.             accesslabel.Visible = false;
  134.             folderlist.Visible = false;
  135.             Folderslabel.Visible = false;
  136.         }
  137.  
  138.         private void button3_Click(object sender, EventArgs e)
  139.         {
  140.            
  141.            
  142.         }
  143.  
  144.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  145.         {
  146.             cursor = folderlist.SelectedIndex;
  147.             if (access.Contains(a[cursor]))
  148.             {
  149.                 accesslabel.Text = "access granted";
  150.                 accesslabel.ForeColor = System.Drawing.Color.Green;
  151.                 accesslabel.Visible = true;
  152.             }
  153.             else
  154.             {
  155.                 accesslabel.Text = "access denied";
  156.                 accesslabel.ForeColor = System.Drawing.Color.Red;
  157.                 accesslabel.Visible = true;
  158.             }
  159.            
  160.         }
  161.  
  162.         private void button1_Click_1(object sender, EventArgs e)
  163.         {
  164.             int f = 2 * x + 3;
  165.             if (textBox1.Text == f.ToString())
  166.             {
  167.                 state = tabrights[user][0];
  168.                 access = tabrights[user][2];
  169.                 folderlist.Items.AddRange(a);
  170.                 folderlist.Visible = true;
  171.                 Folderslabel.Visible = true;
  172.                 textBox1.Visible = false;
  173.                 button1.Visible = false;
  174.                 label1.Visible = false;
  175.                 loginbutton.Visible = (state == "unsigned");
  176.                 Loginlabel.Visible = (state == "unsigned");
  177.                 Loginfield.Visible = (state == "unsigned");
  178.                 Passwordfield.Visible = (state == "unsigned");
  179.                 Passwordlabel.Visible = (state == "unsigned");
  180.                 logoutbutton.Visible = !(state == "unsigned");
  181.                 Statelabel.Text = state;
  182.                 insystem = true;
  183.                 t = 10;
  184.             }
  185.             else
  186.             {
  187.                 errorlabel.Text = "wrong function";
  188.                 textBox1.Visible = false;
  189.                 button1.Visible = false;
  190.                 label1.Visible = false;
  191.             }
  192.         }
  193.  
  194.         private void timer1_Tick(object sender, EventArgs e)
  195.         {
  196.             if (insystem && t>0)
  197.             {
  198.                 t -= 1;
  199.             }
  200.             else
  201.             {
  202.                 insystem = false;
  203.                 verify();
  204.             }
  205.         }
  206.        
  207.        
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement