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

  • SEARCH
  • Home
  • 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 6993625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:47:18+00:00 2026-05-27T19:47:18+00:00

I am just working with username-to-password validation scripting, and I don’t want to mess

  • 0

I am just working with username-to-password validation scripting, and I don’t want to mess with database connections just yet. So I’m just putting certain test emails and passwords into some arrays, then working at validating against those arrays.

I’m getting stuck on the best way to do this, because I actually want to put more pertinent data into each “user” array.

Here’s what I’ve started so far, and you’ll see what I’m shooting for:

<?php

$email = $_POST['email'];
// test emails
$logins = array('john@smith.com'=>'123456','jane@smith.com'=>'123456');

if (!array_key_exists($email, $logins)) {
    echo "that email does not exist, stop here.";
}else{
    echo "email exists, continue...";
}
?>

And this works fine, since it’s simple, but as I needed to add more options into the array, the method changed to this:

<?php
// tester accounts
$user1 = array('email'=>'john@smith.com','password'=>'123456','fullname'=>'john smith','handle'=>'johnny');
$user2 = array('email'=>'jane@smith.com','password'=>'123456','fullname'=>'Jane Smith','handle'=>'janeyS');


// credentials passed from a form
$email = $_POST['email'];
$pass = $_POST['pass'];

/* not quite sure how to validate the $user arrays */

?>

And the user arrays probably will grow with more things related to that user, obviously.
But I’m used to working with database connections, and not straight from PHP arrays.

Can someone throw me a little advice on a simple email/pass validation from multiple php arrays like what I just did above? Or perhaps there’s a better method?

  • 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-27T19:47:19+00:00Added an answer on May 27, 2026 at 7:47 pm

    Turn your users into a $users array.

    $success = (bool) array_filter($users, function($user) use ($email, $pass) {
        return $user['email'] == $email AND $user['password'] == $pass;
    });
    

    This code will loop through all the users in the $users array and return the subset which matched for username and password (should be either 0 or 1).

    Because an empty array is falsy in PHP, casting it to Boolean should give the correct result. You could skip this if you wanted, dependent on the context of using it.

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

Sidebar

Related Questions

Just started working with Mercurial a few days ago and there's something I don't
The goal is to do a simple username/password authentication by querying a database. Until
Im working on an app that need to send a set username and password,
I am working on a project that has to have authentication (username and password)
I'm currently building a username/password/session-management/etc. system for a website I've been working on. I've
We've successfully configured the FOSUserBundle; login, register, reset password, etc, are all working just
I am just working on creating a matrix report in SSRS and when I
I have the following JQuery function about a range slider . It's just working
Just started working with .NET and MVC(1). I'm having a problem wherein in my
Just started working through the Ruby chapter in Mr. Tate's Seven Language in Seven

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.