Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7515339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:46:32+00:00 2026-05-30T00:46:32+00:00

I have built a User class that attempts to lookup the ID for a

  • 0

I have built a User class that attempts to lookup the ID for a user in a MySQL database. If it finds it, it sets the variable SQL_ID to this value, otherwise it leaves it empty.

A separate method (IsValid), called later, returns a boolean telling me if the user, in fact does exist.

I was curious if anyone else would like to comment on my design here, and perhaps offer a more elegant solution. I admit that PHP is not my primary language, and I may be feeling a little OCDish after spending too much time in a non-statically typed language. Perhaps I am seeking validation that this design is sane.

// User -> class for passing around user information. Should only pass around the UserID (a unqiue SQL ID), for security reasons, in a Session object.
    class User {
        private $SQL_ID = "";
        //@todo: Get the User object to actually talk to the other classes. Lol.

        public function __construct($Username, $Password) {
            // Probably want to Base64 encode the values going into and out of the MySQL database, to prevent a SQL Injection attack.
            $query = "SELECT [UserID] FROM [Users] WHERE [Username] = '" . base64_encode($Username) . "' AND [Password] = '" . base64_encode($Password) . "';";
            $data = SQL::DataQuery($query);

            $this->SQL_ID = $data["UserID"];

        }

        // Boolean function to tell us if we have a valid user. Might be able to merge this into the constructor.
        public function IsValid() {
            if($this->SQL_ID == "") {
                return false;
            }

            return true;
        }

        public function GetUserID() {
            return $this->SQL_ID;

        }

        // private $Query = "SELECT [UserID] FROM [Users] WHERE [Username] = '' AND PASSWORD = '';"; // Prototype User query (for selecting a UserID).


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:46:35+00:00Added an answer on May 30, 2026 at 12:46 am

    I don’t think you should have a User object unless the login has been successful. I would use another class (named something like Authenticator) that would be responsible for checking the username and password against the database and returning a User object only if a valid user is found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have built a system that checks user IP, browser, and a random-string
I have a model that has a ForeignKey to the built-in user model in
I have a url that looks like this: http://localhost/store/mens/category/t-shirts/item/a-t-shirt I have a class called
On an ASP.NET-MVC2 project, I have built some user controls that resides in Views\Shared\EditorTemplates
I have created a benchmark class that allows the user to insert for example
In my Qt-based application (built using PyQt 4.8.6), I have a class that is
I have a meta class for the Django User model that I use to
I have built UI, its like a search engine for BioProcess/Disease--> Genes. e.g., User
I have a web-based system built with user login data based on session variables.
I currently have a DetailView for Django's built-in User . url( r'^users/(?P<pk>\d+)/$', DetailView.as_view( model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.