Zubrag.com
September 22, 2018, 01:11:02 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: password-protect.php connect to mssql database  (Read 11353 times)
jaustill
Newbie
*
Posts: 3


« on: November 14, 2006, 03:21:59 PM »

Can you tell me what is wrong?
I added the following code in password-protect.php to access a MSSQL server to pull users and passwords The mssql connection works fine. I noted where I think I am having trouble:

#####################################################
# SETTINGS START
#####################################################

// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line

$hostname = "myhost";
$username = "myuser";
$password = "mypassword";
$dbName = "mydata";

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Table unavailable");

$query = "SELECT SYSPASS_SQL.pass_user, SYSPASS_SQL.pass_user_password FROM SYSPASS_SQL";
$result = MSSQL_QUERY($query);

// my problem seems to be here START

$LOGIN_INFORMATION = array();
while ($row = mssql_fetch_assoc($result)) {
$LOGIN_INFORMATION[$row['pass_user']] = $row['pass_user_password'];
}

// my problem seems to be here END


// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);

#####################################################
# SETTINGS END
#####################################################

///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////

// show usage example

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #1 on: November 14, 2006, 04:13:40 PM »

1. Do you get any error message or you just cannot login?
2. How many users you have?
3. Any special characters in user names, any very long user names? PHP has some restrictions for arrays.

It may be something related to mssql_fetch_assoc behaviour: The keys in the array will only contain the 1st 30 characters of the column name if you have column names longer than that.
Try changing code as follows (added print_r). Does it output correct array, with keys/values you expected to be there?

// my problem seems to be here START

$LOGIN_INFORMATION = array();
while ($row = mssql_fetch_assoc($result)) {
$LOGIN_INFORMATION[$row['pass_user']] = $row['pass_user_password'];
}

echo "<pre>";
print_r($LOGIN_INFORMATION);
echo "</pre>";

// my problem seems to be here END
Logged
jaustill
Newbie
*
Posts: 3


« Reply #2 on: November 14, 2006, 05:05:15 PM »

I do not get any sql errors, I just cannot login, I have 3 users in this test database, there are no special characters.
I added your code and this is the result copied from the browser:

Array
(
    [CDK       ] => CDKPASS 
    [DRD       ] => DRDPASS 
    [JTR       ] => JTRPASS     
)

Please enter password to access this page

Incorrect password.
Login:

Password:


 
Logged
jaustill
Newbie
*
Posts: 3


« Reply #3 on: November 14, 2006, 05:09:16 PM »

Wait I think I've got it.
It looks like it needs a TRIM and a force to upper case on the username and password input to make them match.
I'm a newbie at this, but I'll give that a try.
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #4 on: November 14, 2006, 05:28:43 PM »

Good catch!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC