public static void VerifyPassword(Packet packet)
        {
            using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
            {
                Packet sendPacket;
                dbCon.Username = "******";
                dbCon.Password = "******";
                dbCon.Connect();
                string command  = string.Format("SELECT `username`, `password` FROM `adminDB` WHERE `username`='{0}'", packet.Username);
                string passInDB = dbCon.SearchForString(command, "password");

                bool foo = CryptSharp.Crypter.CheckPassword(packet.Argument, passInDB);

                if (foo)
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Allowed: Logging in with valid credential [{1}]", packet.ClientIP, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                }
                else
                {
                    ConsoleUtils.Print(string.Format("[{0}]'s Denied: Logging in with wrong password [{1}]", packet.ClientIP, packet.Username));
                    sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                }
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                command = string.Empty;
            }
        }
Exemplo n.º 2
0
        public bool HasValidToken()
        {
            try
            {
                string convertedToken;
                string result;
                using (var dbCon = new MySQLDatabaseConnection(System.Net.IPAddress.Parse("127.0.0.1"), "exceeddb"))
                {
                    dbCon.Username = "******";
                    dbCon.Password = "******";
                    dbCon.Connect();

                    string command  = string.Format("SELECT * FROM `adminDB` WHERE `username`='{0}'", Username);
                    string expToken = dbCon.SearchForString(command, "tokenExpired");
                    if (string.IsNullOrEmpty(expToken))
                    {
                        return(false);
                    }

                    DateTime validate = DateTime.Parse(expToken);
                    if (DateTime.Now > validate)
                    {
                        return(false);
                    }

                    result         = dbCon.SearchForString(command, "token");
                    convertedToken = Token.GetString();
                    command        = string.Empty;

                    dbCon.Close();
                }
                return(convertedToken == result);
            }
            catch (Exception e)
            {
                ConsoleUtils.Print("HasValidToken(): " + e.Message);
                return(false);
            }
        }