Help me with this weird error please

This is a discussion on Help me with this weird error please within the C++ Programming forums, part of the General Programming Boards category; Code: #include "Security.h" #include <iostream> #include <SFML/Graphics.hpp> #include <SFML/Window.hpp> Security::Security() { //ctor } Security::~Security() { //dtor } void Security::ErrorMsg() { ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77

    Help me with this weird error please

    Code:
    #include "Security.h"
    
    
    #include <iostream>
    #include <SFML/Graphics.hpp>
    #include <SFML/Window.hpp>
    
    
    
    
    Security::Security()
    {
        //ctor
    }
    
    
    Security::~Security()
    {
        //dtor
    }
    
    
    void Security::ErrorMsg()
    {
        sf::RenderWindow ErrorBox(sf::VideoMode(200,100,32),"Error");
    
    
        sf::Text ErrorText;
        sf::Font ErrorFont;
    
    
        if(ErrorFont.loadFromFile("monospa1.ttf"))
            ErrorText.setFont(ErrorFont);
        ErrorText.setString("Access denied");
        ErrorText.setScale(sf::Vector2f(0.6,0.6));
        ErrorText.setPosition(200/6,130/3);
    
    
        while(ErrorBox.isOpen())
        {
            sf::Event Error;
    
    
            {
                while(ErrorBox.pollEvent(Error))
                {
                    if(Error.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        ErrorBox.close();
                }
            }
    
    
            ErrorBox.draw(ErrorText);
            ErrorBox.display();
        }
    }
    
    
    bool Security::passwords(int passType)
    {
        std::string pass;
    
    
        if(passType == 1)
        {
            std::cout << "Type in your password (MPP ONLY): " << std::endl;
            std::getline(std::cin, pass);
            if( pass == "HelloWorld")
                return true;
            else
                ErrorMsg();
    
    
        }
        else if (passType == 2)
        {
            std::cout << "[Click this window and type in your password]";
            std::cout << "\n\n\n                 Type in your password (Teachers and Students): " << std::endl << std::endl;
            std::cout << "        password: ";
            std::cout << "  " ;
            std::getline(std::cin,pass);
    
    
            if (checkPassword(pass))
                return true;
            else
                ErrorMsg();
        }
    
    
        return false;
    }
    
    
    bool Security::checkPassword(std::string password)
    {
    
    
        passwordArray[0] = "12345";
    
    
        for(int i =0;i<1500;i++)
        {
            if(password == passwordArray[i])
                return true;
        }
    }
    
    
    
    line 45 : error: expected unqualified-id before 'namespace'
    line 89 : error: expected '}' at end of input|
    line 89 : error: expected unqualified-id at end of input|

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,181
    The problem probably lies in Security.h.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    Thanks. One more question; I'm having problem with making something like a "serial key". Something like just simply storing strings somewhere in the code and then use if statement to check valid password, and say that I'm the one who gives out the password. How can I do this without hard-coding? Do you know any method of doing so?

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    You're generally better off putting the includes for standard things such as iostream before your own header files. That way you've unlikely to screw up anything in the compilation of standard libs.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,752
    Passwords usually come down to running with whatever is input. I mean, the password is never compared at all. If it is the right password, it should decrypt whatever you are trying to keep secret.

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Quote Originally Posted by iMalc View Post
    You're generally better off putting the includes for standard things such as iostream before your own header files. That way you've unlikely to screw up anything in the compilation of standard libs.
    Including your own header files before the standard ones has the advantage that you are more likely to make the inclusion dependency correct. If you include standard headers first, you may often forget to include them properly in the other header files. If file Foo.cpp includes its corresponding header Foo.hpp first, it automatically ensures that every standard header is properly included (or else it will not compile). Then you can be sure that someone who includes your Foo.hpp, without including anything else, will not run into something-not-included problem. Precompiled headers make it a bit harder, but you can always turn them off temporarily to check your include directives.
    I never put signature, but I decided to make an exception.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by kmdv View Post
    Including your own header files before the standard ones has the advantage that you are more likely to make the inclusion dependency correct. If you include standard headers first, you may often forget to include them properly in the other header files. If file Foo.cpp includes its corresponding header Foo.hpp first, it automatically ensures that every standard header is properly included (or else it will not compile). Then you can be sure that someone who includes your Foo.hpp, without including anything else, will not run into something-not-included problem. Precompiled headers make it a bit harder, but you can always turn them off temporarily to check your include directives.
    Actually that too is entirely correct. There is no perfect solution.
    Although, something to randomise the order of header inclusions every time you build would be quite interesting.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,920
    Quote Originally Posted by Meerul264 View Post
    Thanks. One more question; I'm having problem with making something like a "serial key". Something like just simply storing strings somewhere in the code and then use if statement to check valid password, and say that I'm the one who gives out the password. How can I do this without hard-coding? Do you know any method of doing so?
    Typically one have a system where one can create passwords, storing them in some sort of database.
    This goes without saying, but all your passwords should be encrypted with non-symmetric keys (one way passwords).
    Then encrypt the inputted password if you must compare it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Error
    By elwad in forum C Programming
    Replies: 9
    Last Post: 08-29-2009, 03:41 PM
  2. Weird error
    By elwad in forum C Programming
    Replies: 4
    Last Post: 05-20-2009, 10:34 AM
  3. Weird Error
    By DanFraser in forum C# Programming
    Replies: 3
    Last Post: 01-06-2006, 06:59 AM
  4. Weird error
    By Mithoric in forum Windows Programming
    Replies: 8
    Last Post: 06-06-2004, 02:11 AM
  5. Weird IE error
    By Ravage in forum Tech Board
    Replies: 16
    Last Post: 03-31-2003, 11:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21