News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How to generate password for SMF 2.X

Started by prathyush, July 23, 2009, 11:45:23 AM

Previous topic - Next topic

prathyush

Hi All

    I am in need to integrate SMF 2.X  to another website. What I want is to use the main site regitration details going to SMF dtabase too. as you know SMF has some special password logic, I just want to create password for main site user to use SMF with their main account. So he does not need to register SMF forum explicitly. Once registred on main site he will be able to login my forum too...

please help

thanks very much in advance

JBlaze

Jason Clemons
Former Team Member 2009 - 2012

Arantor

Depending on what you need, even just SSI might be enough for you.
Holder of controversial views, all of which my own.


prathyush

thanks for helping me.. any sample code snippet will help me alot.. especially genarting password salt..

here is the code I am using but didnot work

$pwd = sha1(strtolower($user).$password);
$salt =  substr(md5(mt_rand()), 0, 4);

can you please tell why this did not work

thanks

Arantor

You don't need to generate the salt.

$pwd should be the same password as in the SMF members table assuming the user name and password are correct.
Holder of controversial views, all of which my own.


Dragooon

Are you using registerMember function(Which is what I'd recommend since it handles extra processing)? If so you need to pass the plaintext password, not the hashed one. Otherwise...you should not be using the quotes....I think that'll generate a parse error.

Something like this should work better...

$register_vars = array(
                        'id_member' => $id_member,
                        'member_name' => $username,
                        'email_address'=> $email,
                        'real_name' => $username,
                        'passwd' => sha1(strtolower($username).$password),
                        'password_salt' => substr(md5(mt_rand()), 0, 4),
                        'posts' => 0,
                        'date_registered' => time(),
                        'is_activated' => 1,
                        'personal_text' => addslashes($smf_settings['default_personalText']),
                        'pm_email_notify' => 1,
                        'id_theme' => 0,
                        'id_post_group' => 4,
                     );


EDIT : I also noticed that you're using $user in password and $username in username, I fixed that up.

prathyush

 :( not worked yet... i tried above code..let me paste it here too

$register_vars = array(
                        'id_member' => $id_member,
                        'member_name' => $username,
                        'email_address'=> $email,
                        'real_name' => $username,
                        'passwd' => sha1(strtolower($username).$password),
                        'password_salt' => substr(md5(mt_rand()), 0, 4),
                        'posts' => 0,
                        'date_registered' => time(),
                        'is_activated' => 1,
                        'personal_text' => addslashes($smf_settings['default_personalText']),
                        'pm_email_notify' => 1,
                        'id_theme' => 0,
                        'id_post_group' => 4,
                      );

its not working  :(

Dragooon


prathyush

$username    = $_POST['username'];
$email       = $_POST['email'];
            
$password    = $_POST['password'];
$extra_fields = array();
$theme_options = array();
smf_registerMember($user_id, $username, $email, $password, $extra_fields, $theme_options);

--------------------------------------------------function follows-----------------------


function smf_registerMember($id_member, $username, $email, $password, $extra_fields = array(), $theme_options = array())
                  {
                     global $smf_settings, $smf_connection;
                  
                     // No connection means no registrations...
                     if (!$smf_connection)
                        return false;
                  
                     // Can't use that username.
                     if (preg_match('~[<>&"\'=\\\]~', $username) != 0 || $username == '_' || $username == '|' || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
                        return false;
                  
                     // !!! Validate username isn't already used?  Validate reserved, etc.?
                  
                     $register_vars = array(
                        'id_member' => $id_member,
                        'member_name' => $username,
                        'email_address'=> $email,
                        'real_name' => $username,
                        'passwd' => sha1(strtolower($username).$password),
                        'password_salt' => substr(md5(mt_rand()), 0, 4),
                        'posts' => 0,
                        'date_registered' => time(),
                        'is_activated' => 1,
                        'personal_text' => addslashes($smf_settings['default_personalText']),
                        'pm_email_notify' => 1,
                        'id_theme' => 0,
                        'id_post_group' => 4,
                      );
                  
                     $register_vars = $extra_fields + $register_vars;
                  
                     mysql_query("
                        INSERT INTO smf_members
                           (" . implode(', ', array_keys($register_vars)) . ")
                        VALUES ('" . implode("', '", $register_vars) . "')");
                     echo "
                        INSERT INTO smf_members
                           (" . implode(', ', array_keys($register_vars)) . ")
                        VALUES ('" . implode("', '", $register_vars) . "')";
                  
                     
                     // Theme variables too?
                     if (!empty($theme_options))
                     {
                        $setString = '';
                        foreach ($theme_options as $var => $val)
                           $setString .= "
                              ($memberID, '$var', '$val'),";
                        mysql_query("
                           INSERT INTO smf_themes
                              (ID_MEMBER, variable, value)
                           VALUES " . substr($setString, 0, -1));
                     }
                  
                     return $id_member;
                  }

[SiNaN]

prathyush, what doesn't work exactly? What's the error you are getting and at which stage?
Former SMF Core Developer | My Mods | SimplePortal

prathyush

I was able to generate password and hash with above code. But it does not seems correct and says username/password incorrect when tried to login

[SiNaN]

What's the username and password you are testing it with? And the hash created in db?
Former SMF Core Developer | My Mods | SimplePortal

Advertisement: