此方法经centos 5.3/5.4 ,apache+php 验证可用。
增加虚拟目录
vi /etc/httpd/conf/httpd.conf 文件最后添加
Alias /svnadmin "/var/www/html/svnadmin/"
<Directory "/var/www/html/svnadmin">
Require valid-user
AuthType Basic
AuthName "SVN user password modify"
AuthUserFile /etc/httpd/svn/htpasswds
</Directory>
我的svn帐号信息存在/etc/httpd/svn/htpasswds ,apache 能够读写此目录
vi /var/www/html/svnadmin/index.php
将以下内容放插入index.php
<?
/*
Alias /svnmodify "/var/www/html/svnadmin/"
<Directory "/var/www/html/svnadmin/">
Require valid-user
AuthType Basic
AuthName "Subversion Tools"
AuthUserFile /etc/httpd/svn/htpasswds
</Directory>
*/
?>
<?
$username = $_SERVER["PHP_AUTH_USER"];
$authed_pass = $_SERVER["PHP_AUTH_PW"];
$input_oldpass = (isset($_REQUEST["oldpass"]) ? $_REQUEST["oldpass"] : "");
$newpass = (isset($_REQUEST["newpass"]) ? $_REQUEST["newpass"] : "");
$repeatpass = (isset($_REQUEST["repeatpass"]) ? $_REQUEST["repeatpass"] : "");
$action = (isset($_REQUEST["action"]) ? $_REQUEST["action"] : "");
if($action!="modify"){
$action = "view";
}
else if($authed_pass!=$input_oldpass){
$action = "oldpasswrong";
}
else if(empty($newpass)){
$action = "passempty";
}
else if($newpass!=$repeatpass){
$action = "passnotsame";
}
else{
$action = "modify";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Reset SVN User Password</title>
</head>
<body>
<?
//action=view 显示普通的输入信息
if ($action == "view"){
?>
<script language = "javaScript">
<!--
function loginIn(myform)
{
var newpass=myform.newpass.value;
var repeatpass=myform.repeatpass.value;
if(newpass==""){
alert("Please enter your new password!");
return false;
}
if(repeatpass==""){
alert("Please re-enter your new password!");
return false;
}
if(newpass!=repeatpass){
alert("New passwords do not match!");
return false;
}
return true;
}
//-->
</script>
<style type="text/css">
<!--
table {
border: 1px solid #CCCCCC;
background-color: #f9f9f9;
text-align: center;
vertical-align: middle;
font-size: 9pt;
line-height: 15px;
}
th {
font-weight: bold;
line-height: 20px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-bottom-style: solid;
color: #333333;
background-color: f6f6f6;
}
input{
height: 18px;
}
.button {
height: 20px;
}
-->
</style>
<br><br><br>
<form method="post">
<input type="hidden" name="action" value="modify"/>
<table width="220" cellpadding="3" cellspacing="8" align="center">
<tr>
<th colspan=2>Reset SVN User Password</th>
</tr>
<tr>
<td align="left" width="60">UserName:</td>
<td align="left"> <?=$username?></td>
</tr>
<tr>
<td align="left" width="60">Current password:</td>
<td><input type=password size=15 name=oldpass></td>
</tr>
<tr>
<td align="left" width="60">New password:</td>
<td><input type=password size=15 name=newpass></td>
</tr>
<tr>
<td align="left" width="60">Confirm new password:</td>
<td><input type=password size=15 name=repeatpass></td>
</tr>
<tr>
<td colspan=2>
<input onclick="return loginIn(this.form)" class="button" type=submit value="Save">
<input name="reset" type=reset class="button" value="Cancel">
</td>
</tr>
</table>
</form>
<?
}
else if($action == "oldpasswrong"){
$msg="The old password you gave is incorrect.";
}
else if($action == "passempty"){
$msg="Please input new password";
}
else if($action == "passnotsame"){
$msg="New passwords do not match.";
}
else{
$passwdfile="/etc/httpd/svn/htpasswds";
$command='"/usr/bin/htpasswd" -b '.$passwdfile." ".$username." ".$newpass;
system($command, $result);
if($result==0){
$msg="User [".$username."]Your new password has been saved,Please re-login.";
}
else{
$msg="User [".$username."]Password change failures,Error".$result.",Please contact qidw@uit.com.cn";
}
}
if (isset($msg)){
?>
<script language="javaScript">
<!--
alert("<?=$msg?>");
window.location.href="<?=$_SERVER["PHP_SELF"]?>"
//-->
</script>
<?
}
?>
</body>
</html>