using QuanLyQuanCafe.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace QuanLyQuanCafe.DAO
{
publicclass AccountDAO
{
privatestatic AccountDAO instance;
publicstatic AccountDAO Instance
{
get { if (instance == null) instance = new AccountDAO(); return instance; }
privateset { instance = value; }
}
privateAccountDAO() { }
publicboolLogin(string userName, string passWord)
{
byte[] temp = ASCIIEncoding.ASCII.GetBytes(passWord);
byte[] hasData = new MD5CryptoServiceProvider().ComputeHash(temp);
string hasPass = "";
foreach (byte item in hasData)
{
hasPass += item;
}
//var list = hasData.ToString();//list.Reverse();string query = "USP_Login @userName , @passWord";
DataTable result = DataProvider.Instance.ExecuteQuery(query, newobject[] { userName, hasPass /*list*/});
return result.Rows.Count > 0;
}
publicboolUpdateAccount(string userName, string displayName, string pass, string newPass)
{
int result = DataProvider.Instance.ExecuteNonQuery("exec USP_UpdateAccount @userName , @displayName , @password , @newPassword", newobject[]{userName, displayName, pass, newPass});
return result > 0;
}
public DataTable GetListAccount()
{
return DataProvider.Instance.ExecuteQuery("SELECT UserName, DisplayName, Type FROM dbo.Account");
}
public Account GetAccountByUserName(string userName)
{
DataTable data = DataProvider.Instance.ExecuteQuery("Select * from account where userName = '" + userName + "'");
foreach (DataRow item in data.Rows)
{
returnnew Account(item);
}
returnnull;
}
publicboolInsertAccount(string name, string displayName, int type)
{
string query = string.Format("INSERT dbo.Account ( UserName, DisplayName, Type, password )VALUES ( N'{0}', N'{1}', {2}, N'{3}')", name, displayName, type, "1962026656160185351301320480154111117132155");
int result = DataProvider.Instance.ExecuteNonQuery(query);
return result > 0;
}
publicboolUpdateAccount(string name, string displayName, int type)
{
string query = string.Format("UPDATE dbo.Account SET DisplayName = N'{1}', Type = {2} WHERE UserName = N'{0}'", name, displayName, type);
int result = DataProvider.Instance.ExecuteNonQuery(query);
return result > 0;
}
publicboolDeleteAccount(string name)
{
string query = string.Format("Delete Account where UserName = N'{0}'", name);
int result = DataProvider.Instance.ExecuteNonQuery(query);
return result > 0;
}
publicboolResetPassword(string name)
{
string query = string.Format("update account set password = N'1962026656160185351301320480154111117132155' where UserName = N'{0}'", name);
int result = DataProvider.Instance.ExecuteNonQuery(query);
return result > 0;
}
}
}
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Bài sau chúng ta sẽ cùng nhau tìm hiểu cách tạo phím tắt.
Đừng quên: “Luyện tập – Thử thách – Không ngại khó”
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Mã hóa mật khẩu trong phần mềm Quản lý quán cafe với C# Winform dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!
Project
Nếu việc thực hành theo hướng dẫn không diễn ra suôn sẻ như mong muốn. Bạn cũng có thể tải xuống PROJECT THAM KHẢO ở link bên dưới!
Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
mã hóa như vậy chắc hẳn là theo 1 tập rules cố định. ai cũng xài nó thì nó thành đại trà phải ko nhỉ? người biết được quy luật này chắc phá được phải ko nhỉ?
CREATE PROCEDURE [dbo].[sp_AddAccount]
@userName NVARCHAR(100),
@displayName NVARCHAR(100),
@typeAccount INT
AS
BEGIN
DECLARE @exitUserName NVARCHAR(100);
DECLARE @passwordAccount NVARCHAR(100) = N'20720532132149213101239102231223249249135100218';
SELECT @exitUserName = userName FROM dbo.Account WHERE userName = @userName
--PRINT @exitUserName;
IF @exitUserName IS NOT NULL -- Nếu tài khoản tồn tại
BEGIN
UPDATE dbo.Account SET displayName = @displayName, passwordAccount = @passwordAccount, typeAccount = @typeAccount WHERE userName = @userName
PRINT N'Update thành công !';
END
ELSE IF @exitUserName IS NULL
BEGIN
INSERT dbo.Account (userName, displayName, passwordAccount, typeAccount) VALUES (@userName, @displayName, @passwordAccount, @typeAccount)
PRINT N'Insert thành công !';
END
END
GO
mã hóa như vậy chắc hẳn là theo 1 tập rules cố định. ai cũng xài nó thì nó thành đại trà phải ko nhỉ? người biết được quy luật này chắc phá được phải ko nhỉ?
tạo PROC SQL:
CREATE PROCEDURE [dbo].[sp_AddAccount]
@userName NVARCHAR(100),
@displayName NVARCHAR(100),
@typeAccount INT
AS
BEGIN
DECLARE @exitUserName NVARCHAR(100);
DECLARE @passwordAccount NVARCHAR(100) = N'20720532132149213101239102231223249249135100218';
SELECT @exitUserName = userName FROM dbo.Account WHERE userName = @userName
--PRINT @exitUserName;
IF @exitUserName IS NOT NULL -- Nếu tài khoản tồn tại
BEGIN
UPDATE dbo.Account SET displayName = @displayName, passwordAccount = @passwordAccount, typeAccount = @typeAccount WHERE userName = @userName
PRINT N'Update thành công !';
END
ELSE IF @exitUserName IS NULL
BEGIN
INSERT dbo.Account (userName, displayName, passwordAccount, typeAccount) VALUES (@userName, @displayName, @passwordAccount, @typeAccount)
PRINT N'Insert thành công !';
END
END
GO
Cho em hỏi là cái mã hóa dãy số ý a
Khi insert nó báo lỗi quá 38 kí tự nên k add đc ạ
Cách khắc phục là gì vậy ạ
Khi Mã hoá mật khẩu rồi thì Sửa đổi thông tin lại không có hiệu lực và mật khẩu phải nhập để đổi mật khẩu là đoạn mã hoá ạ. Cách khắc phục ạ.!