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;
- namespace ProgramadeLogin
- {
- public partial class FrmMenu : Form
- {
- public FrmMenu()
- {
- InitializeComponent();
- }
- private void FrmMenu_FormClosed(object sender, FormClosedEventArgs e)
- {
- //fecha a aplicação por completo
- Application.Exit();
- }
- }
- }
- 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.Security.Cryptography;
- namespace ProgramadeLogin
- {
- public partial class frmLogin : Form
- {
- //dados do utilizador
- string utilizador = "Flavio";
- string password = "1234";
- public frmLogin()
- {
- InitializeComponent();
- }
- private void btn_cancelar_Click(object sender, EventArgs e)
- {
- //fechar a aplicação
- Application.Exit();
- }
- private void btn_entrar_Click(object sender, EventArgs e)
- {
- //verificar se o login é correto
- if (text_utilizador.Text == "" || text_password.Text == "")
- return;
- bool entrar = true;
- string codigo = CriarMD5(text_password.Text);
- //verifica se houver falhas de introdução dos dados
- if (text_utilizador.Text != utilizador || codigo != CriarMD5(password))
- {
- MessageBox.Show("Dados de login invalidos.");
- entrar = false;
- }
- //se o login é correto, abre o menu principal
- if (entrar)
- {
- this.Hide();
- FrmMenu f = new FrmMenu();
- f.ShowDialog();
- }
- }
- private void check_visualizar_pasasword_CheckedChanged(object sender, EventArgs e)
- {
- //visualiza ou esconde o texto da senha
- if (check_visualizar_pasasword.Checked)
- {
- //mostra a passaword
- text_password.PasswordChar = '\0';
- }
- else
- {
- //esconde a password
- text_password.PasswordChar = '*';
- }
- }
- private string CriarMD5(string texto)
- {
- //encriptar com o algoritimo MD5 o texto fornecido
- MD5 criador = MD5.Create();
- byte[] inputs = Encoding.ASCII.GetBytes(texto);
- byte[] hash = criador.ComputeHash(inputs);
- StringBuilder final = new StringBuilder();
- for (int i = 0; i < hash.Length; i++)
- {
- final.Append(hash[i].ToString("X2"));
- }
- return final.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement