如何通过WEB方式安全添加系统用户

在网上看到一些通过php直接添加系统用户的解决方法,这些方法都在脚本中保存系统超级用户密?很大的安全性问题 。这里提供的方法是通过php在前台添加用户、密码记录到mysql数据库中,后台通过cron 隔时(时间可以自己设定)执行添加用户的程序 。程序中都没有记录系统超级用户密码,这样能保证系统的安 全 。如下为添加用户的后台程序,这个程序只是为很粗糙的演示程序,功能为把addornot=0的用户加入系统中 而已,仅供读者参考 。php添加用户信息到数据库的程序略去 。程序在RedHat6.0 下通过 adduserfromdb.pl#!/usr/bin/perluse DBI;$dbuser = "xxxx";$dbpasswd = "xxx";$db = "xxxx";$dbh = DBI->connect("DBI:mysql:$db",$dbuser,$dbpasswd);$query = "select user,passwd from usertable where addornot=0";$sth = $dbh->prepare($query);$rv = $sth->execute or die "Can"t execute the query:$sth->
errstrn";while(@row = $sth->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 "$saltt$row[1]n";$encrypt_passwd = crypt($row[1],$salt);#print $encrypt_passwd."n";$add_exec = "/usr/sbin/useradd -p ".$encrypt_passwd." ".$row[0];#对useradd增加参数,可以控制用户的组别、目录、登陆与否、shell等等#print $add_exec."n";system($add_exec); }#1;用户信息表usertable:CREATE TABLE usertoadd (user tinytext NOT NULL,passwd tinytext NOT NULL,addornot tinyint(4) DEFAULT "0" NOT NULL);
【如何通过WEB方式安全添加系统用户】

    推荐阅读