Esempio n. 1
0
        // 返回UserID
        public static int CheckRepeatUserName(string userID, string userName)
        {
            SqlConnection conn = DAO.Connection();
            // 查询账户是否存在
            string queryUserName = "******" + userName + "'";

            try
            {
                // 打开数据链接
                conn.Open();
                //Console.WriteLine("检查用户名{0}是否存在...", user.UserName);
                // 新建一个命令对象
                SqlCommand command = conn.CreateCommand();
                // 写入SQL语句
                command.CommandText = queryUserName;
                // 读取对应的结果集
                SqlDataReader reader = command.ExecuteReader();
                if (!reader.HasRows)
                {
                    return(0);
                }
                else
                {
                    int    rows = 0;
                    string id   = "";
                    string name = "";
                    while (reader.Read())
                    {
                        id   = reader["UserID"].ToString();
                        name = reader["UserName"].ToString();
                        rows++;
                    }
                    //Console.WriteLine(id);
                    if (rows == 1)
                    {
                        if (id == userID)
                        {
                            reader.Close();
                            conn.Close();
                            return(1);
                        }
                        else
                        {
                            reader.Close();
                            conn.Close();
                            if (name != userName)
                            {
                                return(0);
                            }
                            return(2);
                        }
                    }
                    else
                    {
                        reader.Close();
                        conn.Close();
                        return(3);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message.ToString());
                return(4);
            }
        }
Esempio n. 2
0
        // 返回UserID
        public static int ForgetPassword(string UserID, string UserName, string NewPsw, string ConfirmPsw, string CheckName)
        {
            int minLength = 3;

            if (UserID.Trim() == "")
            {
                return(1);
            }
            else
            {
                if (CheckName == null)
                {
                    return(2);
                }
                else
                {
                    if (Convert.ToBoolean(UserName.CompareTo(CheckName)))
                    {
                        return(3);
                    }
                    else
                    {
                        if (NewPsw.Length < minLength)
                        {
                            return(4);
                        }
                        else if (!Utils.CheckValidChar(NewPsw))
                        {
                            return(5);
                        }
                        else
                        {
                            if (Convert.ToBoolean(ConfirmPsw.CompareTo(NewPsw)))
                            {
                                return(6);
                            }
                            else
                            {
                                SqlConnection conn      = DAO.Connection();
                                string        updatePsw = "UPDATE [User] SET Password='******' WHERE UserID = '" + UserID + "'";
                                //Console.WriteLine(updatePsw);
                                try
                                {
                                    conn.Open();
                                    SqlCommand command = conn.CreateCommand();
                                    command.CommandText = updatePsw;
                                    int rows = command.ExecuteNonQuery();
                                    conn.Close();
                                    if (rows > 0)
                                    {
                                        return(0);
                                    }
                                    else
                                    {
                                        return(-1);
                                    }
                                }
                                catch (Exception exception)
                                {
                                    Debug.WriteLine(exception.Message.ToString());
                                    return(-1);
                                }
                            }
                        }
                    }
                }
            }
        }