开发者

Codeigniter/PHP: Creating users in batch with TankAuth

I am interested in creating bulk users/passwords in a batch using TankAuth for CodeIgniter. I asked this question on the CI forums but got no responses:

http://codeigniter.com/forums/viewthread/110993/P330/#837327

Google searches don't turn up much besides my thread a开发者_运维问答s the third result and a bunch of unrelated sites.

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=create+batch+users+tankauth

Has anyone successfully done this using a recursion algorithm? If so, can you post some code to get me going on the right path? Thanks!

Versions of software:

CI 1.7.3

TankAuth 1.0.7

PHP 5.x

EDIT 2/15:

Just in case anyone is looking for a solution to this, here's a function that is basically the same one I used (there were some other parameters, but this should get you going):

function batchReg()
{
    $this->load->model('mymodel');

    // connect to the database
    $this->mymodel->dbconnect();

    // build it
    $query = "SELECT user, email, pass from newusers ORDER BY user ASC";

    // ship it
    $result = mysql_query($query);

    // loop it
    while ($row = mysql_fetch_array($result))
    {
        $data = $this->tank_auth->create_user($row['user'], $row['email'], $row['pass'], FALSE);
        print_r($data);
        echo "<p>";
    }

}

Just ping batchReg() from the controller to put it into action!


Sounds like a simple loop operation to me

somehow (whatever the source) get your usernames in a iterable form like an array $user_list

we'll say it looks like this

Array(
    Array(
        [username] => '...',
        [email]    => '...',
        [password] => '',     //leave password empty
    ),
    Array(
        [username] => '...',
        [email]    => '...',
        [password] => '',     //leave password empty
    ),
    ... etc.
)

Then create a simple looping routine to process the new registrations, storing the password back into the array, so you will then have a complete list of logins, new (randomized) passwords and emails.

//loop by referance in order to properly store the generated password
foreach($user_list as &$user) {

    //generate 8 char password and store it
    $user['password'] = substr(uniqid(),2,8);

    //run register routine (not sure on tank auth's specific syntax
    $this->tankauth->register($user['username'],$user['email'],$user['password'],FALSE);
}

Then at the end your $user_list contains all the new passwords for your users.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜