Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin Tips & Tricks
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Validating a username and password from external pages
sknight
Join Date: Nov 2008
Posts: 4

 

Show Printable Version Email this Page Subscription
sknight sknight is offline 01-24-2011, 10:00 PM

Seems like rocket science to get the proper informatiion but here is some code I whipped up this afternoon.

I needed a way for users of my site to log into my main site using their forum username and password and I thought this would help others trying to do the same.

PHP Code:
<?
$server=ENTER VBULLETIN SERVER IP HERE;
$databaseusername=ENTER VBULLETIN DATABASE USERNAME HERE;
$databasepassword=ENTER VBULLETIN DATABASE PASSWORD HERE;
$databasename=ENTER VBULLETIN DATABASE NAME HERE
$chandle =mysql_connect ($server, $databaseusername", $databasepassword);
if (!mysql_select_db($datababasename, $chandle)) die("can't select database");
$username=mysql_real_escape_string($_REQUEST['username']);
$password=mysql_real_escape_string($_REQUEST['password']);
$pass=false;
$passworderr="please enter a password";
$usernameerr="please enter a username";
if (($username<>"") && ($password<>""))
    {
    $sql="SELECT username,password,salt FROM `user` WHERE username='".$username."' LIMIT 0 , 1";
    $sresult = mysql_query($sql);
    if (!$sresult) die ("bad sql in username lookup ".$sql." ".mysql_error());
    $row=mysql_fetch_array($sresult);
    if (mysql_affected_rows()==1)
        {
        if (md5(md5($password) . $row['salt']) == $row['password'])
            $pass=true;
        else
            $passworderr="<b>invalid password</b>";
        }
    else
        $usernameerr="<b>username not found</b>";
    }

if ($pass==true)
    {?>
    Thank you for logging in
<?     }
else
    {?>
    <form type="post">
    <table>
        <tr>
        <td align=right><? echo $usernameerr ?></td>
        <td><input type=text name=username value="<?echo $username ?>" width=20></td>
        </tr>
        <td>
        <tr>
        <td align=right><? echo $passworderr ?></td>
        <td><input type=password name=password value="<?echo $password ?>" width=20>
        <input type=submit value="log in">
        </td>
        </tr>
    </table>
<?    }?>
Reply With Quote
  #2  
Old 01-30-2011, 06:31 PM
tom001 tom001 is offline
 
Join Date: Aug 2009
Posts: 42
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What do you do with this?

We need to know.
Reply With Quote
  #3  
Old 03-01-2011, 01:52 PM
Fuhrmann Fuhrmann is offline
 
Join Date: May 2010
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice one, thanks!!
Reply With Quote
  #4  
Old 04-03-2011, 06:59 PM
Gursimran Gursimran is offline
 
Join Date: Jun 2008
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have wordpress installed in the root. I don't show its login box to my users, neither ask them to register in wordpress. I wonder if I can use this integration in wordpress pages?
Reply With Quote
  #5  
Old 07-18-2011, 04:52 PM
bigtime bigtime is offline
 
Join Date: Jun 2002
Location: Houston, Texas
Posts: 171
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the code. There's a typo.

$row['password])

Should be:

PHP Code:
$row['password']) 
Thanks,

Tim
www.SuppYo.com
Reply With Quote
Reply


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 08:23 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03874 seconds
  • Memory Usage 2,236KB
  • Queries Executed 20 (?)
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
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)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