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.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace beadando_i7vs1c
- {
- public partial class LogInForm : Form
- {
- private DataClasses1DataContext _db;
- public LogInForm()
- {
- InitializeComponent();
- _db = new DataClasses1DataContext();
- }
- private void LogInForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- WelcomeForm wf = new WelcomeForm();
- wf.Show();
- }
- private void btBack_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(tbUsername.Text))
- {
- MessageBox.Show("Nem adott meg felhasználónevet.");
- return;
- }
- if (String.IsNullOrWhiteSpace(tbPassword.Text))
- {
- MessageBox.Show("Nem adott meg jelszót.");
- return;
- }
- string username = this.tbUsername.Text;
- string password = this.tbPassword.Text;
- string codedpass = this.EncodePass(password);
- User loginuser = CheckForUserAndPass(username, codedpass);
- if (loginuser == null)
- {
- MessageBox.Show("Nem megfelelő felhasználónevet vagy jelszót adott meg.");
- }
- else
- {
- this.Hide();
- UserWelcome uw = new UserWelcome(loginuser);
- uw.Show();
- }
- }
- private User CheckForUserAndPass(string username, string password)
- {
- try
- {
- User queryUser = (from un in _db.Users
- where un.UserName == username && un.Password == password
- select un).First();
- return queryUser;
- }
- catch (InvalidOperationException)
- {
- return null;
- }
- }
- private string EncodePass(string password)
- {
- byte[] codedpass = new UTF8Encoding().GetBytes(password);
- byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(codedpass);
- string encoded = BitConverter.ToString(hash).ToLower();
- return encoded;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement