Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2008
    Location
    Vancouver, Canada
    Posts
    650

    Arrow [HELP] Automate User Creation with PHP

    I have successfully created a user account using the code below:
    PHP Code:
    <?php
    system
    ("useradd someuser");
    ?>
    But when I run this below:
    PHP Code:
    <?php
    system
    ("passwd someuser");
    // I had code here, but it didn't work -_-
    ?>
    It requires me to manually type in the passwords. Does anyone know how I could make PHP set the password of a user?

    Also to run this code I am using inside ROOT (Debian):
    # php ./somefile.php
    Has anyone successfully set the password of a user using PHP before?

    Thanks in advanced
    Tailored VPS offers fully customizable VPS Hosting
    Powered by OpenVZ | Servers located in the USA | 99.9% Uptime

  2. #2
    Join Date
    Apr 2004
    Location
    UK
    Posts
    1,331
    Is it possible to specify the password in-line? Type man passwd to see what parameters the program takes
    .
    @jmedwards
    - find me on Twitter!
    Kayako help desk software - we help our customers help their customers

  3. #3
    Join Date
    Aug 2008
    Location
    Vancouver, Canada
    Posts
    650
    No it isn't possible. I have tried:
    # useradd someuser -p somepass
    But it doesn't set the password to 'somepass'.

    I am currently searching on Google for a solution.
    Tailored VPS offers fully customizable VPS Hosting
    Powered by OpenVZ | Servers located in the USA | 99.9% Uptime

  4. #4
    Join Date
    Apr 2004
    Location
    UK
    Posts
    1,331
    Perhaps you could write a bash script to perform the commands in sequence (with the use of variables), and execute this via PHP
    .
    @jmedwards
    - find me on Twitter!
    Kayako help desk software - we help our customers help their customers

  5. #5
    Join Date
    Aug 2008
    Location
    Vancouver, Canada
    Posts
    650
    A bash script could work. I will give it a try when I get home.

    Thanks
    Tailored VPS offers fully customizable VPS Hosting
    Powered by OpenVZ | Servers located in the USA | 99.9% Uptime

  6. #6
    Join Date
    Nov 2001
    Location
    Vancouver
    Posts
    2,416
    man pw, specifically the -h option and please note the cautions.
    “Even those who arrange and design shrubberies are under
    considerable economic stress at this period in history.”

  7. #7
    Join Date
    Mar 2009
    Location
    /usr/bin/perl
    Posts
    971
    adding variables into a "system" call in a php script running with root permissions sounds like a notoriously bad idea from a security standpoint. If you're doing this for anything other than your personal amusement I would urge you to throw in some sanity checks.

  8. #8
    Join Date
    Aug 2008
    Location
    Vancouver, Canada
    Posts
    650
    Quote Originally Posted by jarrodsl View Post
    adding variables into a "system" call in a php script running with root permissions sounds like a notoriously bad idea from a security standpoint. If you're doing this for anything other than your personal amusement I would urge you to throw in some sanity checks.
    It is for a test on one of my home servers so I don't have to worry about security issues.
    Tailored VPS offers fully customizable VPS Hosting
    Powered by OpenVZ | Servers located in the USA | 99.9% Uptime

  9. #9
    Join Date
    Aug 2008
    Location
    Vancouver, Canada
    Posts
    650
    Using a bash script works

    Thanks for all the help!
    Tailored VPS offers fully customizable VPS Hosting
    Powered by OpenVZ | Servers located in the USA | 99.9% Uptime

  10. #10
    Join Date
    May 2009
    Posts
    766
    Not having read the man page, I'd suggest an expect script over a bash script. This is exactly the type of application that expect was designed for.

    Of course, the easiest solution since you're not worried about security measures would be to just manually edit the shadow/passwd file.

Similar Threads

  1. cPanel/WHM Automate Account Creation
    By Skillz in forum Hosting Software and Control Panels
    Replies: 47
    Last Post: 12-27-2008, 09:51 AM
  2. whmcs - how to automate account creation and welcome mail
    By phpost in forum Hosting Software and Control Panels
    Replies: 8
    Last Post: 08-27-2008, 05:27 PM
  3. Hey Clientexec users how to get CE to automate account creation.
    By Energizer Bunny in forum Hosting Software and Control Panels
    Replies: 4
    Last Post: 07-31-2006, 04:28 PM
  4. Automate Hosting Account Creation )Customer Solution)
    By Jay01 in forum Hosting Software and Control Panels
    Replies: 7
    Last Post: 03-29-2006, 10:31 PM
  5. IIS: Automate creation of virtual dirs of web sites
    By Canadaka in forum Hosting Security and Technology
    Replies: 0
    Last Post: 07-08-2004, 01:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •