예제 #1
0
파일: CUser.cs 프로젝트: Pavlo7/AEVIProject
        private List <STPassCache> convert_passcache(string data)
        {
            List <STPassCache> ret = new List <STPassCache>();

            if (string.IsNullOrEmpty(data))
            {
                return(ret);
            }

            STPassCache item;

            string[] words = data.Split(',');
            foreach (string cp in words)
            {
                if (cp.Length > 1)
                {
                    string[] cache = cp.Split(':');
                    if (cache.Length == 2)
                    {
                        item              = new STPassCache();
                        item.password     = cache[0];
                        item.passwordsalt = cache[1];
                        ret.Add(item);
                    }
                }
            }

            return(ret);
        }
예제 #2
0
파일: CUser.cs 프로젝트: Pavlo7/AEVIProject
        public int AddPassToPassCache(string login, STPassCache pc, out string msg)
        {
            int ret = 0;

            msg = null;

            SqlConnection connect;
            Log           log = new Log(LogPath);

            string passcache = null;

            try
            {
                List <STPassCache> lstpc = new List <STPassCache>();
                int retvalue             = GetPassCache(login, out lstpc, out msg);
                //   lstpc.Add(pc);

                int cnt = 1;
                passcache = string.Format("{0}:{1},", pc.password, pc.passwordsalt);

                foreach (STPassCache item in lstpc)
                {
                    if (cnt < 4)
                    {
                        passcache += string.Format("{0}:{1},", item.password, item.passwordsalt);
                        cnt++;
                    }
                }

                connect = new SqlConnection(ConnectionString);
                connect.Open();

                if (connect.State == ConnectionState.Open)
                {
                    string query = "UPDATE dbo.Users SET PassCache=@1 WHERE Login=@2";

                    SqlCommand cmd = new SqlCommand(query, connect);
                    cmd.Parameters.Add(crp(SqlDbType.VarChar, "@1", passcache, false));
                    cmd.Parameters.Add(crp(SqlDbType.VarChar, "@2", login, false));
                    SqlDataReader reader = cmd.ExecuteReader();

                    connect.Close();
                }
                else
                {
                    return(1);
                }
            }
            catch (Exception ex) { log.Write(LogType.Error, ex.Message); ret = -1; msg = ex.Message; }
            return(ret);
        }