1.要用md5加密,要添加程序集system.Web。
2.蓝色下划线,是有个失效日期。
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 ItCastSIM { public partial class FrmLogin : Form { public FrmLogin() { InitializeComponent(); } #region 登录 -void btnLogin_Click(object sender, EventArgs e) /// <summary> /// 登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { string userName = txtUserName.Text.Trim(); string userPwd = txtPwd.Text.Trim(); MODEL.Person per = pm.Login(userName); // if (per == null) { MessageBox.Show("用户名不存在"); } else { if (per.PPwd == System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(userPwd, "md5")) //md5加密 { //MessageBox.Show(this.DialogResult.ToString()); none this.DialogResult = DialogResult.OK; //这个窗体你做了相应的合理的操作,那么窗体就会关闭 #region 不能关闭起始窗体 //MessageBox.Show(per.PCName+":登录成功"); //FrmMain frm = new FrmMain(); //frm.Text = "欢迎你:" + per.PCName; ////this.Hide(); ////this.Visible = false; //设置隐藏属性 //frm.ShowDialog(); //frm.DialogResult = DialogResult.OK; //this.Close();//关闭当前窗体,如果一个窗体是从另外一个窗体打开的,如果关闭起始的打开窗体,那么通过这个起始窗体打开的所有窗体都会关闭。。也就说明,如果关闭起始窗体,那么就相当于退出应用程序 #endregion } else { MessageBox.Show("密码错误了"); } } }
namespace BLL { public class PersonManager { DAL.PersonService ps = new DAL.PersonService(); #region 登录判断 +MODEL.Person Login(string name, string pwd) /// <summary> /// 登录判断 /// </summary> /// <param name="name"></param> /// <param name="pwd"></param> /// <returns></returns> public MODEL.Person Login(string name) { return ps.Login(name); } /// <summary> /// 登录判断 /// </summary> /// <param name="name"></param> /// <param name="pwd"></param> /// <returns></returns> public MODEL.Person Login(string name) { return ps.Login(name); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; namespace DAL { public class PersonService { #region 登录判断 +MODEL.Person Login(string name, string pwd) /// <summary> /// 登录判断 /// 传入登录名,根据登录名获取对应的行记录,将行记录转换为对象 /// </summary> /// <param name="name"></param> /// <param name="pwd"></param> /// <returns></returns> public MODEL.Person Login(string name) { string sql = "select person.*,cname from person inner join classes on Person.PCID=Classes.CID where ploginname=@name and pisdel=@isDel"; SqlParameter[] ps ={ new SqlParameter("name",name), new SqlParameter("isDel",false) }; //1.如果是得到增加删除和修改以及结果集的第一行第一列值那么就使用创建连接对象,命令对象,调用命令对象的方法 //2.如果是想得到结果集多行多列(多个值),一般不会使用SqlDataReader,而使用SqlDataAdapter DataTable dt = SqlHelper.ExcuteTable(sql, ps); //根据唯一约束的原理,表中应该只有一条记录 MODEL.Person person = null; if (dt.Rows.Count > 0)//判断有没有返回记录 { person = new MODEL.Person(); DataRowToPerson(dt.Rows[0], person); //person是引用类型,方法对其进行修改, 原始值也会变化 } return person; } /// 将人员结果集表中的行转换为对象 /// </summary> /// <param name="row"></param> /// <param name="person"></param> private void DataRowToPerson(DataRow row, MODEL.Person person) { person.PID = Convert.ToInt32(row[0]); person.PCID = Convert.ToInt32(row[1]); person.PType = Convert.ToInt32(row[2]); person.PLoginName = row[3].ToString(); person.PCName = row[4].ToString(); person.PPYName = row[5].ToString(); person.PPwd = row[6].ToString(); person.PGender = Convert.ToBoolean(row[7]); if (!(row[8] is DBNull) && !(string.IsNullOrEmpty(row[8].ToString()))) { person.PEmail = row[8].ToString(); } person.PAreas = row[9].ToString(); person.PIsDel = Convert.ToBoolean(row[10]); person.PAddTime = Convert.ToDateTime(row[11]); person.Cname = row[12].ToString(); //得到班级信息 } #endregion
}
}