How to securely add system users through WEB

Source: Internet
Author: User
Article Title: How to securely add system users through WEB. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
On the Internet, we can see some solutions for directly adding system users through php. These methods are all saved in the script system's Superuser password? Security issues. The method provided here is to add users and password records to the mysql database through php at the front end, and execute programs for adding users through cron at intervals (time can be set by yourself. The system Superuser password is not recorded in the program, which ensures system security. The following is the background program for adding users. This program is just a rough demo program. The function is to add addornot = 0 users to the system for your reference only. The php program that adds user information to the database is omitted. The program passes in RedHat6.0.
  
Adduserfromdb. pl
  
#! /Usr/bin/perl
Use DBI;
$ Dbuser = "xxxx ";
$ Dbpasswd = "xxx ";
$ Db = "xxxx ";
  
$ Dbh = DBI-> connect ("DBI: mysql: $ db", $ dbuser, $ dbpasswd );
$ Query = "select user, passwd from usertable where addornot = 0 ";
$ Something = $ dbh-> prepare ($ query );
$ Rv = $……-> execute or die "Can't execute the query: $……-> errstr \ n ";
While (@ row = $ th-> fetchrow_array ){
# Print "user =". $ row [0]. "\ n ";
# Print "password =". $ row [1]. "\ n ";
@ Saltchars = (a. z, A. Z, 0. 9 );
Srand (time | $ );
$ Salt = $ saltchars [rand ($ # saltchars)]. $ saltchars [rand ($ # saltchars)];
# Print "$ salt \ t $ row [1] \ n ";
$ Encrypt_passwd = crypt ($ row [1], $ salt );
# Print $ encrypt_passwd. "\ n ";
$ Add_exec = "/usr/sbin/useradd-p". $ encrypt_passwd. "". $ row [0];
# Add parameters to useradd to control user groups, directories, logon or not, and shell.
# Print $ add_exec. "\ n ";
System ($ add_exec );
}
#1;
  
User information table
Usertable:
  
Create table usertoadd (
User tinytext not null,
Passwd tinytext not null,
Addornot tinyint (4) DEFAULT '0' NOT NULL
);

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.