Beispiel #1
0
        public bool SaveUser(ref UserInfo model, UserInfo user, ref string strError)
        {
            try
            {
                if (model.ID <= 0)
                {
                    model.Creater = user.UserNo;
                }
                else
                {
                    model.Modifyer = user.UserNo;
                }
                if (!model.Password.Equals("不要加密或更新"))
                {
                    UFSoft.U8.Framework.Login.UI.clsLogin netLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();
                    model.Password = netLogin.EnPassWord(model.Password);
                }

                return(_db.SaveUser(ref model));
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 登陆U8系统确认身份,并得到登录字符串
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="accID">帐套名</param>
        /// <param name="year">财务年度</param>
        /// <param name="inf">struct类型</param>
        /// <param name="customerName">登录者名字</param>
        /// <param name="connectionString">生成的数据库连接字符串</param>
        /// <param name="errMsg">错误信息</param>
        /// <returns>0:正确,非0,错误</returns>
        static public int Login(string userID, string password, string accID, string year, info inf,
            out string customerName, out string connectionString, out string errMsg)
        {

            customerName = "";
            connectionString = "";
            errMsg = "";
            string ERPService = "";     //ERP服务器地址
            string DBService = "";
            string sqlUser = "";
            string sqlPassword = "";

            try
            {
                sqlUser = inf.sqlUser;
                sqlPassword = inf.sqlPassword;
                ERPService = inf.ERPService; //string.Format("UFDATA_{0}_{1}",accID,year);//inf.ERPService;
                DBService = inf.DBService;

                connectionString = "user id=" + sqlUser + ";password="******";data source='" + DBService
                        + "';persist security info=True;initial catalog=UFDATA_" + accID + "_" + year
                        + ";Connection Timeout=30";
            }
            catch (Exception ex)
            {
                errMsg = "配置文件错误!" + ex.Message;
                return -1;
            }
            UFSoft.U8.Framework.Login.UI.clsLogin netLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();
            try
            {
                string SQL = "select top 1 cUser_Name from ufsystem..ua_user where cUser_id=N'" + userID + "' and cPassword='******'";
                DataSet Ds_User = new DataSet();
                int i = OperationSql.GetDataset(SQL, connectionString, out Ds_User, out errMsg);
                if (i != 0)
                {
                    return -2;
                }
                else
                {
                    if (Ds_User.Tables[0].Rows.Count == 0)
                    {
                        errMsg = "用户名或者密码错误";
                        return -2;
                    }
                    else
                    {
                        customerName = Ds_User.Tables[0].Rows[0][0].ToString();
                        return 0;
                    }
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return -2;
            }
        }
Beispiel #3
0
        public bool UserLogin(ref UserInfo user, ref string strError)
        {
            if (DateTime.Today >= Convert.ToDateTime("2016-10-15") && !securityAndRegister.EncryptionHelper.CheckRegist())
            {
                strError = "登陆异常!该用户不存在";
                return(false);
            }
            if (string.IsNullOrEmpty(user.LoginDevice))
            {
                user.LoginDevice = user.LoginIP;
            }
            string   LoginIP = user.LoginIP;
            DateTime CurrentTime;
            string   strSql = string.Empty;

            if (user.UserNo.ToUpper() != "ADMIN")
            {
                UFSoft.U8.Framework.Login.UI.clsLogin netLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();
                user.Password = netLogin.EnPassWord(user.Password);
                strSql        = string.Format("SELECT GETDATE() CurrentTime,V_User.* FROM V_User WHERE UserNo = '{0}' AND password = '******'", user.UserNo, user.Password);
            }
            else
            {
                strSql = string.Format("SELECT GETDATE() CurrentTime,V_User.* FROM V_User WHERE UserNo = '{0}' ", user.UserNo);
            }
            //strSql = string.Format("SELECT GETDATE() CurrentTime,V_User.* FROM V_User WHERE UserNo = '{0}'", user.UserNo);

            UserInfo model;

            using (SqlDataReader odr = OperationSql.ExecuteReader(CommandType.Text, strSql))
            {
                if (odr.Read())
                {
                    User_Func func = new User_Func();
                    model       = func.GetModelFromDataReader(odr);
                    CurrentTime = odr["CurrentTime"].ToDateTime();

                    if (model == null)
                    {
                        strError = "用户实例化失败";
                        return(false);
                    }
                    else if (model.UserStatus == 2)
                    {
                        strError = string.Format("用户【{0}】已停用", model.UserName);
                        return(false);
                    }
                    else if (model.IsDel == 2)
                    {
                        strError = string.Format("用户【{0}】已删除", model.UserName);
                        return(false);
                    }

                    if (model.BIsOnline)
                    {
                        if (model.UserType == 1)
                        {
                            if (!string.IsNullOrEmpty(user.LoginIP) && model.LoginIP.Length + user.LoginIP.Length >= 100 && model.LoginIP.IndexOf(user.LoginIP) <= -1)
                            {
                                strError = string.Format("超级管理员用户【{0}】已超过登录次数上限,目前共【{1}】处登录{2}请先登出或联系管理员清除后重试", model.UserName, model.LoginIP.Split(';').Length, Environment.NewLine);
                                return(false);
                            }
                            else if (!string.IsNullOrEmpty(user.LoginDevice) && model.LoginDevice.Length + user.LoginDevice.Length >= 200 && model.LoginDevice.IndexOf(user.LoginDevice) <= -1)
                            {
                                strError = string.Format("超级管理员用户【{0}】已超过登录次数上限,目前共【{1}】处登录{2}请先登出或联系管理员清除后重试", model.UserName, model.LoginDevice.Split(';').Length, Environment.NewLine);
                                return(false);
                            }
                        }
                        else
                        {
                            if (model.LoginIP != user.LoginIP)
                            {
                                string LoginAddress = string.IsNullOrEmpty(model.LoginDevice) ? model.LoginIP : model.LoginDevice;
                                if (!model.LoginIP.StartsWith("PC"))
                                {
                                    strError = string.Format("用户【{0}】已于【{1}】在【{2}】处登录{3}请先登出或联系管理员清除后重试", model.UserName, model.LoginTime, LoginAddress, Environment.NewLine);
                                    return(false);
                                }
                                else if ((CurrentTime - model.LoginTime.ToDateTime()).TotalMilliseconds < 1500000)
                                {
                                    strError = string.Format("用户【{0}】正在【{1}】处使用{2}请先登出或联系管理员清除后重试", model.UserName, LoginAddress, Environment.NewLine);
                                    return(false);
                                }
                            }
                        }
                    }

                    model.LoginTime   = CurrentTime;
                    model.LoginIP     = user.LoginIP;
                    model.LoginDevice = user.LoginDevice;

                    user = model;
                }
                else
                {
                    strSql = string.Format("SELECT COUNT(1) FROM V_User WHERE UserNo = '{0}' ", user.UserNo);
                    int i = OperationSql.ExecuteScalar(CommandType.Text, strSql).ToInt32();
                    if (i <= 0)
                    {
                        strError = "登陆异常!该用户不存在";
                        return(false);
                    }
                    else
                    {
                        strError = "密码输入错误";
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="user"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool Login(User user, DBInfo info)
        {
            if (user == null)
            {
                return(false);
            }

            user.ConnectionString = string.Format(@"user id={0};password={1};data source={2};persist security info=True;initial catalog=UFDATA_{3}_{4};Connection Timeout=30", info.SqlUser, info.SqlPassword, info.DBServer, user.AccID, user.Year);
            bool flag = false;

            try
            {
                UFSoft.U8.Framework.Login.UI.clsLogin netLogin = new UFSoft.U8.Framework.Login.UI.clsLogin();
                string strSql = string.Format("select top 1 cUser_Name from ufsystem..ua_user where cUser_id=N'{0}' and cPassword='******'", user.UserID, netLogin.EnPassWord(user.Password));
                //u8Login = new clsLogin();
                //isLogin = flag = u8Login.Login(ref sSubId, ref sAccID, ref sYear, ref sUserID, ref sPassword, ref sDate, ref sServer, ref sSerial);
                DataTable dt = DBHelperSQL.QueryTable(user.ConnectionString, strSql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    user.UserName = dt.Rows[0][0].ToString();
                    flag          = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(flag);
        }