Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 09-12-2011, 08:08 PM
fleccy fleccy is offline
 
Join Date: Jun 2003
Location: England
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default External Site login from application (salt, MD5 issue)

Hi all,

I've been pulling my hair out trying to figure out what's wrong. I think my method is wrong.

The code works fine with plain text passwords but I can't seem to figure out how to use salt!

PHP Code:
<?php

$username 
$_POST['username'];
$password $_POST['password'];

if (
selectFromDB() == md5(md5($password).$count['salt'])) {
   echo 
"Accept";
} else {
   echo 
"Denied";
}

function 
selectFromDB() {
    
    global 
$username;
    
//Database service vars
    
$databasehost "localhost";
    
$databasename "nes";
    
$databasetable "test";
    
$databaseusername ="root";
    
$databasepassword "password";

    
$con mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
        
mysql_select_db($databasename) or die(mysql_error());

    
    
$query "SELECT password,salt FROM user WHERE username='$username'";
    
    
$result mysql_query($query);
    
$count mysql_num_rows($result);

    if (
$count)
    {
        
$output mysql_result($result0);        
        return 
$output;
    }
    else
    {
        return 
"0";
    }
    
mysql_free_result($result);
    
mysql_close($con);
}

?>
Thanks for your time
Reply With Quote
  #2  
Old 09-15-2011, 10:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't see how you're getting the salt value, but maybe that's what you mean when you say you can't figure out how to use it.

I think I'd make a "check password" function where you pass it the username and password and it returns true or false. Maybe like:

PHP Code:
function checkPassword($username$password
{
    
//Database service vars
    
$databasehost "localhost";
    
$databasename "nes";
    
$databasetable "test";
    
$databaseusername ="root";
    
$databasepassword "password";

    
$con mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
     
mysql_select_db($databasename) or die(mysql_error());
    
    
$query "SELECT password,salt FROM user WHERE username='" mysql_real_escape_string
($username) . "'";
    
    
$result mysql_query($query);
    
$row mysql_fetch_array($result);
    
mysql_free_result($result);
    
mysql_close($con);

    if (
$row)
        return 
md5(md5($password) . $row['salt']) === $row['password'];

    return 
false;


(BTW, I haven't tried this at all).
Reply With Quote
  #3  
Old 09-16-2011, 10:47 AM
fleccy fleccy is offline
 
Join Date: Jun 2003
Location: England
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your help. I still can't seem to get it working! Not sure where I'm going wrong, I need it to echo Accept or Denied if the password is correct but I keep going wrong somewhere.
Reply With Quote
  #4  
Old 09-16-2011, 11:36 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It works for me, after fixing a couple of typos in the code I posted (I've fixed them above as well). I used code like this to test it:

PHP Code:
$username $_POST['username'];
$password $_POST['password'];

if (
checkPassword($username$password))
   echo 
"Accept";
else 
   echo 
"Denied"

One thing: I don't know where your password is coming from, but I think the vb code runs the password through md5 in javascript before sending it, but also has to allow for browsers with javascript disabled. So when it checks the password, it checks both ways. I guess you could do the same thing by using this code:

PHP Code:
if (checkPassword($username$password) OR checkPassword($usernamemd5($password)))
   echo 
"Accept";
else 
   echo 
"Denied"
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03792 seconds
  • Memory Usage 2,207KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete