Sharing _php Tutorials with PHP to modify Linux or UNIX passwords

Source: Internet
Author: User
Tags php book
Required Tools and Installation:

You must install the following tools and software:

– A shell script that modifies the password;

–sudo access rights;

–apache or LIGHTTPD Web server;

–php Service-side program.

Step 1: Install a shell script that can modify the user's password

The script can actually be used to modify the password of a Linux user (already tested in Linux and FreeBSD).

Example: Shell script code

#!/bin/sh # \ Exec expect-f "$0″${1+" $@ "} set password [lindex $argv 1] Spawn passwd [lindex $argv 0] Sleep 1 expect" as Sword: "Send" $password \ r "expect" Assword: "Send" $password \ r "Expect EOF run shell script (download link):

$ chpasswd Username password Download the script and copy it to your Web root directory or other location on the Web server (user-readable):

$ CP chpasswd/var/www/OR, if you use the LIGHTTPD Web server:

$ CP chpasswd/home/lighttpd Step 2: Execute command with sudo as root

The Apache or LIGHTTPD Web server will use non-root permissions immediately after it has entered the background. This can be a good way to prevent password changes, like the passwd command requires root permission to modify the password of other user accounts.

Typically, Apache 2 uses www-data users, lighttpd use LIGHTTPD users (both ordinary users, non-root users). Log in using the root user, and then execute the following command:

# Visudo Now your Web server allows you to execute a password modification script (CHPASSWD). If you are using the Apache Web server, execute the following command:

Www-data all=nopasswd:/var/www/chpasswd or, if you are using a LIGHTTPD Web server, execute the following command:

httpd all=nopasswd:/home/lighttpd/chpasswd Save and exit files.

Step 3: Create a PHP-based interface

Now you need to write a PHP script. Here is an example of a PHP script. You can modify it according to your needs. At the very least, you need to set the location of the shell script correctly. Open the PHP script and locate the Shellscript line:

$shellscript = "SUDO/HOME/LIGHTTPD/CHPASSWD"; modify Shellscript point to the correct location. The source code for PHP is downloaded from here:

Step 4: Run the script

Enter the net address in your Web browser address bar and you will see the username and password prompt:

If the password changes successfully, you will get a confirmation prompt:

For some reasons, if the password modification fails, you can refer to the following tips for more detailed error messages:

Step 5: Security

Never run the above script directly through the HTTP protocol. Instead, use the HTTPS protocol.

Put the script into a password-protected directory.

Never trust the user's input. The above PHP script is just an example. In a real-world production environment, you need to consider using more powerful user input validation. Discussing the security of PHP programming is beyond the scope of this article. You can refer to a good PHP book or use your favorite search engine to search for related websites.

http://www.bkjia.com/PHPjc/324889.html www.bkjia.com true http://www.bkjia.com/PHPjc/324889.html techarticle Required Tools and installation: You must install the following tools and software: – Shell scripts that modify passwords, –sudo access, –apache or LIGHTTPD Web servers, –php service-side programs. Step ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.