- [C#] Hướng dẫn giải nén file *.rar với tiến trình progress bar winform
- [C#] Chia sẻ source code make Crazy Error Message Effect Bomb Windows
- [C#] Lập trình ứng dụng theo mô hình MVP Model-View-Presenter Pattern Winform
- [C#] Giới thiệu và những thứ hay ho từ thư viện System.Reactive của Microsoft
- [C#] Hướng dẫn tạo ứng dụng Chat với GPT sử dụng Open AI API
- [DEVEXPRESS] Tạo month picker trên DateEdit Winform C#
- [DATABASE] Cách sử dụng và lưu ý khi sử dụng khóa ngoại (Foreign Key) trong Sqlserver
- [C#] Garbage Collector (GC) là gì? Cách giải phóng bộ nhớ trên ứng dụng Winform khi các đối tượng không còn sử dụng
- [C#] Cách tính độ tương phản màu sắc Contrast Color mà con người có thể nhìn thấy được
- [C#] Hướng dẫn mã hóa mật khẩu tài khoản ứng dụng đúng chuẩn Men
- [C#] Sử dụng Open AI Chat GPT viết ứng dụng Count down timer có hiệu ứng trên winform
- [DATABASE] Chia sẻ dữ liệu Pantone Color sql và json api
- [SQLSERVER] Tạo mã sản phẩm tự động như: SP0001, SP0002, SP0003... sử dụng Trigger
- [C#] Hướng dẫn kiểm tra phiên bản NET Framework cài đặt ở máy tính
- [C#] Hướng dẫn đọc file excel đơn giản sử dụng thư viện Epplus
- [C#] ConcurrentBag là gì và cách sử dụng nó trong lập trình bất đồng bộ
- [C#] AutoResetEvent là gì và cách sử dụng
- [DEVEXPRESS] Chia sẻ source code cách tạo biểu đồ sơ đồ tổ chức công ty Org Chart trên Winform C#
- [C#] Hướng dẫn tạo Auto Number trên Datagridview winform
- [DATABASE] Hướng dẫn tạo Procedure String Split in Mysql
[C#] Hướng dẫn tạo Form Đăng nhập kết nối cơ sở dữ liệu Sql server winform
Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách tạo form đăng nhập Login Form sqlserver trên lập trình C#, Winform.
[C#] Login Form sqlserver step by step
Dưới đây là giao diện mình thiết kế form login sử dụng thư viện Guna2 Framework.
Để cài đặt thư viện Guna 2 Framework, các bạn có thể tìm kiếm trên website laptrinhvb.net nhé.
Trong bài viết, cung cấp cho các bạn các kỷ thuật như sau:
- Kết nối cơ sở dữ liệu Sqlserver sử dụng thư viện Dapper
- Sử dụng Guna2 Framework thiết kế form hiện đại
- Ghi nhớ đăng nhập
- Mã hóa md5 khi lưu trữ thông tin login
Chi tiết các bạn có thể xem video hướng dẫn từng bước:
Source code C#:
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 LoginDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
guna2ShadowForm1.SetShadowForm(this);
this.Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
this.BeginInvoke(new Action(() =>
{
//if (string.IsNullOrEmpty(Properties.Settings.Default.username))
//{
txtUsername.Text = Properties.Settings.Default.username;
txtPassword.Text = Properties.Settings.Default.password;
chkRemember.Checked = Properties.Settings.Default.isRemember;
//}
}));
}
private void btnLogin_Click(object sender, EventArgs e)
{
var username = txtUsername.Text.Trim();
var password = txtPassword.Text.Trim();
if (string.IsNullOrEmpty(username))
{
MessageBox.Show("Enter your username");
txtUsername.Focus();
return;
}
if (string.IsNullOrEmpty(password))
{
MessageBox.Show("Enter your my password");
txtPassword.Focus();
return;
}
var sql = $"select count(*) from tbl_users where username='{username}' and password='{GetMD5(password)}'";
var isLogin = Convert.ToInt32(SQLHelper.ExecQuerySacalar(sql)) > 0 ? true : false;
if (isLogin)
{
//MessageBox.Show("Login Successful!");
if (chkRemember.Checked)
{
Properties.Settings.Default.username = username;
Properties.Settings.Default.password = password;
Properties.Settings.Default.isRemember = true;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
}
else
{
Properties.Settings.Default.username = "";
Properties.Settings.Default.password = "";
Properties.Settings.Default.isRemember = false;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
}
var frmMain = new FrmMain(username);
frmMain.Show();
this.Hide();
}
else
{
MessageBox.Show("Username or password wrong!");
}
}
private String GetMD5(string txt)
{
String str = "";
Byte[] buffer = System.Text.Encoding.UTF8.GetBytes(txt);
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
buffer = md5.ComputeHash(buffer);
foreach (Byte b in buffer)
{
str += b.ToString("X2");
}
return str;
}
}
}
Thanks for watching!
PASS GIẢI NÉN: laptrinhvb.net