vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin Tips & Tricks (https://vborg.vbsupport.ru/forumdisplay.php?f=239)
-   -   Validating a username and password from external pages (https://vborg.vbsupport.ru/showthread.php?t=257812)

sknight 01-24-2011 10:00 PM

Validating a username and password from external pages
 
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>
<?    }?>


tom001 01-30-2011 06:31 PM

What do you do with this?

We need to know.

Fuhrmann 03-01-2011 01:52 PM

Nice one, thanks!!

Gursimran 04-03-2011 06:59 PM

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?

bigtime 07-18-2011 04:52 PM

Thanks for the code. There's a typo.

$row['password])

Should be:

PHP Code:

$row['password']) 

Thanks,

Tim
www.SuppYo.com


All times are GMT. The time now is 08:40 AM.

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.01059 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete