/
Login.aspx.cs
81 lines (70 loc) · 2.33 KB
/
Login.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
public partial class Login : System.Web.UI.Page
{
DataAccess data = new DataAccess();
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "Thành viên đăng nhập";
}
public static string GetMD5(string str)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] bHash = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
StringBuilder sbHash = new StringBuilder();
foreach (byte b in bHash)
{
sbHash.Append(String.Format("{0:x2}", b));
}
return sbHash.ToString();
}
protected void btnDangnhap_Click(object sender, EventArgs e)
{
try
{
string tenDN = logintenDN.Text;
string matKhau = loginmatKhau.Text;
matKhau = GetMD5(matKhau);
ThanhVien tv = data.GetAThanhVien(tenDN, matKhau);
if (tv == null)
{
lblmsg.Text = "Sai tên đăng nhập hoặc mật khẩu";
lblmsg.CssClass = "alert alert-danger col-sm-12";
}
else
{
Session["thanhvien"] = tv;
Response.Redirect("/");
}
}
catch (Exception ex)
{
Response.Write("<script>alert(" + ex.Message + ");</script>");
}
}
protected void btnDangKy_Click(object sender, EventArgs e)
{
ThanhVien tv = new ThanhVien();
tv.tenDN = txtTenDN.Text;
string matKhau = txtMk.Text;
tv.matKhau = GetMD5(matKhau);
tv.email = txtEmail.Text;
tv.hoTen = txtHoten.Text;
tv.gioiTinh = Convert.ToInt32(ddGioitinh.Text);
tv.ngayTao = Convert.ToDateTime(DateTime.Now);
if (txtNgaySinh.Text!=null)tv.ngaySinh = Convert.ToDateTime(txtNgaySinh.Text);
if (txtDiaChi.Text != null) tv.diaChi = txtDiaChi.Text;
tv.trangThai = 1;
if (tv.gioiTinh == 1) tv.anhDaiDien = "/Upload/Avatar/boy.jpg";
else tv.anhDaiDien = "/Upload/Avatar/girl.jpg";
data.ThemThanhVien(tv);
Session["thanhvien"] = tv;
Response.Redirect("/");
}
}