/// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public int Update(ManagerInfo mi)
        {
            //定义参数集合,动态添加
            List <MySqlParameter> listPs = new List <MySqlParameter>();
            //构造update的sql语句
            string sql = "update ManagerInfo set MName=@MName";

            listPs.Add(new MySqlParameter("@MName", mi.MName));
            //判断是否修改密码
            if (!mi.MPwd.Equals("这是原来的密码吗?"))
            {
                sql += ",MPwd=@MPwd";
                listPs.Add(new MySqlParameter("@MPwd", Md5Helper.EncryptString(mi.MPwd)));
            }
            sql += ",MType=@MType where MId=@MId";
            listPs.Add(new MySqlParameter("@MType", mi.MType));
            listPs.Add(new MySqlParameter("@MId", mi.MId));
            //构造语句的参数
            //MySqlParameter[] ps =
            //{
            //    new MySqlParameter("@MName", mi.MName),
            //    new MySqlParameter("@MPwd", mi.MPwd),
            //    new MySqlParameter("@MType", mi.MType),
            //    new MySqlParameter("@MId", mi.MId)
            //};
            //执行语句并返回结果
            return(MysqlHelper.ExecuteNonQuery(sql, listPs.ToArray()));
        }
        public LoginState Login(string name, string pwd, out int type)
        {
            //设置type默认值,登陆不成功时,不会作用此值
            type = -1;
            //根据用户名进行对象的查询
            ManagerInfo mi = miDal.GetByName(name);

            if (mi == null)
            {
                //用户名错
                return(LoginState.NameError);
            }
            else
            {
                if (mi.MPwd.Equals(Md5Helper.EncryptString(pwd)))
                {
                    //密码正确
                    type = mi.MType;
                    return(LoginState.Ok);
                }
                else
                {
                    //密码错误
                    return(LoginState.PwdError);
                }
            }
        }
Exemple #3
0
        public async Task <IActionResult> Login(string username, string password, string returnUrl)
        {
            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                var values = new Dictionary <string, string>
                {
                    { "username", username },
                    { "password", password }
                };

                var response = await _client.PostAsync(new Uri(_webApiSettings.AuthenticateUrl),
                                                       new StringContent(JsonConvert.SerializeObject(values), Encoding.UTF8, "application/json"));

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    HttpContext.Session.SetString("username", username);
                    HttpContext.Session.SetString("password", Md5Helper.EncryptString(password));
                    ViewBag.Logged = true;

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        var path = returnUrl.Split("/");
                        return(RedirectToAction(path[2], path[1]));
                    }

                    return(View("Success"));
                }
            }

            ViewBag.error = "Invalid Credentials";
            return(View("index"));
        }
Exemple #4
0
        /// <summary>
        /// 修改管理员,特别注意:密码
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public int Update(ManagerInfo mi)
        {
            //为什么要进行密码的判断:
            //答:因为密码值是经过md5加密存储的,当修改时,需要判断用户是否改了密码,如果没有改,则不变,如果改了,则重新进行md5加密

            //定义参数集合,可以动态添加元素
            List <SQLiteParameter> listPs = new List <SQLiteParameter>();
            //构造update的sql语句
            string sql = "update ManagerInfo set mname=@name";

            listPs.Add(new SQLiteParameter("@name", mi.MName));
            //判断是否修改密码
            if (!mi.MPwd.Equals("这是原来的密码吗"))
            {
                sql += ",mpwd=@pwd";
                listPs.Add(new SQLiteParameter("@pwd", Md5Helper.EncryptString(mi.MPwd)));
            }
            //继续拼接语句
            sql += ",mtype=@type where mid=@id";
            listPs.Add(new SQLiteParameter("@type", mi.MType));
            listPs.Add(new SQLiteParameter("@id", mi.MId));

            //执行语句并返回结果
            return(SqliteHelper.ExecuteNonQuery(sql, listPs.ToArray()));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //获取用户输入的信息
            string name  = UserName.Text;
            string pwd   = PassWord.Password;
            string Dname = DisplayName.Text;
            string OKpwd = OKPassWord.Password;

            //调用代码
            if (name == "" || pwd == "" || Dname == "" || OKpwd == "")
            {
                MessageBox.Show("各项不可为空!");
            }
            else
            {
                if (pwd != OKpwd)
                {
                    MessageBox.Show("密码不一致!");
                }
                else
                {
                    UsersBll   usersBll = new UsersBll();
                    UsersModel user     = usersBll.CheckByName(name, Dname, Md5Helper.EncryptString(pwd));
                    if (user != null)
                    {
                        MessageBox.Show("该用户已存在!");
                    }
                    else
                    {
                        MessageBox.Show("注册成功!");
                    }
                }
            }
        }
        public LoginState Login(string name, string pwd, out int type)
        {
            //设置type默认值,如果为此值时,不会使用
            type = -1;
            //根据用户名进行对象的查询
            ManagerInfo mi = miDal.GetByName(name);

            if (mi == null)
            {
                //用户名错误
                return(LoginState.NameError);
            }
            else
            {
                //用户名正确
                if (mi.Mpwd.Equals(Md5Helper.EncryptString(pwd)))
                {
                    //密码正确
                    //登录成功
                    type = mi.Mtype;
                    return(LoginState.Ok);
                }
                else
                {
                    //密码不正确
                    return(LoginState.PwdError);
                }
            }
        }
Exemple #7
0
        public bool IsTrueNameAndPwd(string name, string pwd, out int id)
        {
            id = int.MaxValue;
            var isExist = IsExistName(name);

            if (isExist)
            {
                string   sql        = "Select * from [UserInfo] where [UserName]='" + name + "' and [Delflag]=" + false;;
                var      dataTable  = SqlHelper.GetDataTable(sql);
                var      listEntity = new UserInfo().GetList(dataTable);
                UserInfo userInfo   = new UserInfo();
                if (listEntity.Count == 1)
                {
                    userInfo = (UserInfo)listEntity[0];
                    id       = userInfo.Id;
                }
                else
                {
                    return(false);
                }
                string pwds = Md5Helper.EncryptString(pwd);
                if (pwds.Equals(userInfo.PassWord))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string Dname    = Application.Current.MainWindow.DataContext.ToString();
            string oldpwd   = OldPassWord.Password;
            string newpwd   = NewPassWord.Password;
            string newokpwd = NewPassWord.Password;

            //调用代码
            if (newpwd != newokpwd)
            {
                MessageBox.Show("新密码不一致!");
            }
            else
            {
                if (oldpwd == newpwd)
                {
                    MessageBox.Show("新旧密码不能相同!");
                }
                else
                {
                    UsersBll   usersBll = new UsersBll();
                    UsersModel user     = usersBll.CheckByDName(Dname, Md5Helper.EncryptString(newpwd));
                    if (user.PassWord.Equals(Md5Helper.EncryptString(oldpwd)))
                    {
                        user.OK = true;
                        MessageBox.Show("修改密码成功!");
                    }
                    else
                    {
                        MessageBox.Show("原始密码错误!");
                    }
                }
            }
        }
Exemple #9
0
        private void Login_Click(object sender, RoutedEventArgs e)
        {
            //获取用户输入的信息
            string name = UserName.Text;
            string pwd  = PassWord.Password;

            //调用代码
            if (UserName.SelectedText == null)
            {
                MessageBox.Show("用户名或密码为空");
            }
            else
            {
                UsersBll   usersBll = new UsersBll();
                UsersModel user     = usersBll.GetByName(name);
                if (user == null)
                {
                    MessageBox.Show("用户名错误");
                }
                else
                {
                    if (user.PassWord.Equals(Md5Helper.EncryptString(pwd)))
                    {
                        //将登陆者传递给主窗口
                        Application.Current.MainWindow.DataContext = user.DisplayName;
                        Application.Current.MainWindow.Content     = new ViewDataGrid();
                    }
                    else
                    {
                        MessageBox.Show("密码错误");
                    }
                }
            }
        }
Exemple #10
0
        public void EncryptString_And_DecryptString_Get_Same_Value(string password)
        {
            //Act
            var valueEncrypted = Md5Helper.EncryptString(password);
            var valueDecrypted = Md5Helper.DecryptString(valueEncrypted);

            //Assert
            Assert.Equal(password, valueDecrypted);
            Assert.IsType <string>(valueDecrypted);
        }
Exemple #11
0
        public int Update(UserInfo ui)
        {
            List <SqlParameter> listPs = new List <SqlParameter>();
            //构造update的sql语句
            string sql = "update T_User set pwd=@pwd where uid=@name";

            listPs.Add(new SqlParameter("@pwd", Md5Helper.EncryptString(ui.Pwd)));
            listPs.Add(new SqlParameter("@name", ui.Name));

            return(SqlServerHelper.ExecuteNonQuery(CommandType.Text, sql, listPs.ToArray()));
        }
Exemple #12
0
        /// <summary>
        /// Insert an item
        /// </summary>
        /// <param name="mi">Object of ManagerInfo</param>
        /// <returns></returns>
        public int Insert(ManagerInfo mi)
        {
            string sql = "insert into ManagerInfo(mname,mpwd,mtype) values(@name,@pwd,@type)";

            SQLiteParameter[] ps =
            {
                new SQLiteParameter("@name", mi.MName),
                new SQLiteParameter("@pwd",  Md5Helper.EncryptString(mi.MPwd)),//Encapsulate with md5
                new SQLiteParameter("@type", mi.MType)
            };
            return(SqliteHelper.ExecuteNonQuery(sql, ps));
        }
Exemple #13
0
        public void EncryptString_Assert_Return()
        {
            //Arrange
            var valueToHash = "aPassword";

            //Act
            var hash = Md5Helper.EncryptString(valueToHash);

            //Assert
            Assert.IsType <string>(hash);
            Assert.NotEqual(valueToHash, hash);
            Assert.NotEmpty(hash);
        }
        /// <summary>
        /// 注册用户时候,将新注册用户加入表中
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public int Insert(UserInfo ui)
        {
            string sql = "insert into UserInfo(uName, uPwd, uType) values(@name, @pwd, @type)";

            SQLiteParameter[] p =
            {
                new SQLiteParameter("@name", ui.uName),
                new SQLiteParameter("@pwd",  Md5Helper.EncryptString(ui.uPwd)),
                new SQLiteParameter("type",  ui.uType)
            };
            //执行插入操作
            return(SqlHelper.ExecuteNonQuery(sql, p));
        }
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="mi">ManagerInfo类型的对象</param>
        /// <returns></returns>
        public int Insert(ManagerInfo mi)
        {
            //构造insert语句
            string sql = "insert into ManagerInfo(MName,MPwd,MType) values(@MName,@MPwd,@MType)";

            //构造sql语句的参数
            MySqlParameter[] ps = //使用数组初始化器
            {
                new MySqlParameter("@MName", mi.MName),
                new MySqlParameter("@MPwd",  Md5Helper.EncryptString(mi.MPwd)),
                new MySqlParameter("@MType", mi.MType)
            };
            //执行插入操作
            return(MysqlHelper.ExecuteNonQuery(sql, ps));
        }
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="mi">ManagerInfo类型的对象</param>
        /// <returns>受影响的行数</returns>
        public int Insert(ManagerInfo mi)
        {
            //构造insert语句
            string sql = "insert into ManagerInfo(mname, mpwd,mtype) values(@name,@pwd,@type)";

            //构造sql语句的参数,使用数组初始化器
            SQLiteParameter[] ps =
            {
                new SQLiteParameter("@name", mi.MName),
                new SQLiteParameter("@pwd",  Md5Helper.EncryptString(mi.Mpwd)),//将密码进行加密
                new SQLiteParameter("@type", mi.Mtype)
            };
            //执行插入操作
            return(SqliteHelper.ExecuteNonQuery(sql, ps));
        }
        //Update
        public int Update(ManagerInfo mi)
        {
            List <SQLiteParameter> listPs = new List <SQLiteParameter>();
            string sql = "update ManagerInfo set mname=@name";

            listPs.Add(new SQLiteParameter("@name", mi.MName));
            if (!mi.MPwd.Equals("这是原来的密码"))
            {
                sql += ",mpwd=@pwd";
                listPs.Add(new SQLiteParameter("pwd", Md5Helper.EncryptString(mi.MPwd)));
            }
            sql += ",mtype=@type where mid = @id";
            listPs.Add(new SQLiteParameter("@type", mi.MType));
            listPs.Add(new SQLiteParameter("@id", mi.Mid));

            return(SqliteHelper.ExecuteNonQuery(sql, listPs.ToArray()));
        }
        static void Main(string[] args)
        {
            DataManager dataManager = new DataManager();
            UserInfo    userInfo    = new UserInfo();

            userInfo.UserName = "******";
            userInfo.PassWord = Md5Helper.EncryptString("Admins");
            userInfo.Remark   = "超级管理员";
            var isSuccess = DataManager.UserInfoBLL.Add(userInfo);

            if (isSuccess)
            {
                Console.WriteLine("成功");
            }
            else
            {
                Console.WriteLine("不成功");
            }
            Console.ReadKey();
        }
Exemple #19
0
        /// <summary>
        /// 插入新账户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int Insert(UserInfo user)
        {
            string sql = "insert into UserInfo(uCode, uPassword, uName) values(@uCode, @uPassword, @uName)";
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter()
            {
                ParameterName = "@UCode", SqlValue = user.UCode
            });
            parameters.Add(new SqlParameter()
            {
                ParameterName = "@UName", SqlValue = user.UName
            });
            parameters.Add(new SqlParameter()
            {
                ParameterName = "@UPassword", SqlValue = Md5Helper.EncryptString(user.UPassword)
            });

            return(SqlHelper.ExecuteNonQuery(sql, parameters.ToArray()));
        }
        //修改管理员,特别注意,密码是否修改
        public int Update(ManagerInfo mi)
        {
            //定义参数集合,可以动态添加元素
            List <SQLiteParameter> listPs = new List <SQLiteParameter>();
            //构造update的sql语句
            string sql = "update ManagerInfo set mname=@name";

            listPs.Add(new SQLiteParameter("@name", mi.MName));
            if (!mi.Mpwd.Equals("这是原来的密码吗"))
            {
                sql += ", mpwd=@pwd";
                listPs.Add(new SQLiteParameter("@pwd", Md5Helper.EncryptString(mi.Mpwd)));
            }
            //继续拼接语句
            sql += ", mpwd=@pwd, mtype=@type where mid=@id";
            listPs.Add(new SQLiteParameter("@type", mi.Mtype));
            listPs.Add(new SQLiteParameter("@id", mi.MId));
            //执行语句并返回结果
            return(SqliteHelper.ExecuteNonQuery(sql, listPs.ToArray()));
        }
        public LoginState login(string name, string pwd)
        {
            UserInfo ui = udDal.getByName(name);

            if (ui == null)
            {
                return(LoginState.UserNameError);
            }
            else
            {
                if (ui.uPwd == Md5Helper.EncryptString(pwd))
                {
                    //密码正确
                    return(LoginState.Ok);
                }
                else
                {
                    return(LoginState.PasswordError);
                }
            }
        }
Exemple #22
0
        //登录
        public LoginState Login(string name, string pwd)
        {
            UserInfo ui = uiDal.GetbyName(name);

            if (null == ui)
            {
                //用户名错误
                return(LoginState.NameError);
            }
            if (ui.Pwd.Equals(Md5Helper.EncryptString(pwd)))
            {
                //密码正确
                //登录成功
                return(LoginState.Ok);
            }
            else
            {
                //密码错误
                return(LoginState.PwdError);
            }
        }
Exemple #23
0
        /// <summary>
        /// 登录,根据账户和密码判断是否能登录
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="userPwd"></param>
        /// <returns>返回登录状态</returns>
        public LoginState Login(string userCode, string userPwd)
        {
            UserInfo user = uiDal.GetByUCode(userCode);

            if (user == null || user.UDelFlag == 1)
            {
                // 无此账户, UDelFlag为1 表示被删除
                return(LoginState.WithoutAcc);
            }
            else if (user.UPassword.Equals(Md5Helper.EncryptString(userPwd)))
            {
                // 密码正确,登录成功
                return(LoginState.Success);
            }
            else
            {
                // 账户或密码错误
                // 填写的密码与此账户的密码不一致
                return(LoginState.Failure);
            }
        }
Exemple #24
0
        public LoginState Login(string name, string pwd, out int type)
        {
            type = -1;
            ManagerInfo mi = miDal.GetByName(name);

            if (mi == null)
            {
                return(LoginState.NameError);
            }
            else
            {
                if (mi.MPwd.Equals(Md5Helper.EncryptString(pwd)))
                {
                    type = mi.MType;
                    return(LoginState.ok);
                }
                else
                {
                    return(LoginState.PwdError);
                }
            }
        }
Exemple #25
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            Huang_System f1 = (Huang_System)this.Owner;//将本窗体的拥有者强制设为Form1类的实例f

            if (!CheckInput())
            {
                return;
            }
            //添加时候 默认 id 为maxValue
            if (entityId == int.MaxValue)
            {
                //添加
                var name = txtUserName.Text.Trim();
                if (!IsContainsSpital(name))
                {
                    lbltips.Visible   = true;
                    lbltips.ForeColor = Color.Red;
                    lbltips.Text      = "用户名不能使用特殊字符";
                    return;
                }
                var isExist = DataManager.UserInfoBLL.IsExistName(name);
                if (!isExist)
                {
                    UserInfo userInfo = new UserInfo();
                    userInfo.UserName = txtUserName.Text.Trim();
                    userInfo.PassWord = Md5Helper.EncryptString(txtPwd.Text.Trim());
                    userInfo.Remark   = txtRmark.Text.Trim();
                    var isSuccess = DataManager.UserInfoBLL.Add(userInfo);
                    if (!isSuccess)
                    {
                        MessageBox.Show("操作失败!");
                        return;
                    }
                    else
                    {
                        this.lbltips.Visible = false;
                        this.lbltips.Text    = "";
                        this.Close();
                    }
                }
                else
                {
                    lbltips.Visible   = true;
                    lbltips.ForeColor = Color.Red;
                    lbltips.Text      = "存在相同用户名,请更换用户名";
                }
            }
            else
            {
                UserInfo userInfo = new UserInfo();
                var      name     = txtUserName.Text.Trim();
                //检查名称是否含有特殊字符
                if (!IsContainsSpital(name))
                {
                    lbltips.Visible   = true;
                    lbltips.ForeColor = Color.Red;
                    lbltips.Text      = "用户名不能使用特殊字符,修改失败";
                    return;
                }
                //检查修改后名称是否符合要求
                var isExist = DataManager.UserInfoBLL.IsExistName(name);
                if (isExist)
                {
                    lbltips.Visible   = true;
                    lbltips.ForeColor = Color.Red;
                    lbltips.Text      = "存在相同用户名,请更换用户名";
                    return;
                }
                userInfo.UserName = name;
                if (txtPwd.Text.Trim() != "123456789")
                {
                    userInfo.PassWord = Md5Helper.EncryptString(txtPwd.Text.Trim());
                }
                userInfo.Remark = txtRmark.Text.Trim();
                userInfo.Id     = entityId;
                var isSuccess = DataManager.UserInfoBLL.Edit(userInfo);
                if (!isSuccess)
                {
                    MessageBox.Show("操作失败!");
                    return;
                }
                this.Close();
            }
            //属性界面
            f1.GetDgv(f1.SelectIndex);
        }