nbsp;
p=wcsstr(User,L“User=");
if(p)
wcscpy(User,p+5);
else
User=NULL;
p=wcsstr(Password,L“Password=");
if(p)
wcscpy(Password,p+9);
else
Password=NULL;
p=wcsstr(NewPassword1,L“NewPassword1=");
if(p)
wcscpy(NewPassword1,p+13);
else
NewPassword1=NULL;
p=wcsstr(NewPassword2,L“NewPassword2=");
if(p)
wcscpy(NewPassword2,p+13);
else
NewPassword2=NULL;
}
//调用API函数更改口令
NET_API_STATUS ChangePassword(){
return NetUserChangePassword
(NULL,User,Password,NewPassword1);
//NULL为用户所属服务器
//User为用户账户名
//Password为旧密码
//NewPassword1为新密码
//函数返回值为NET_API_STATUS类型
}
void main(){
char* pRequestMethod;
pRequestMethod=getenv
(“REQUEST_METHOD");
if (pRequestMethod == NULL){
cout < <
“This program is designed to run as a CGI script\n";
return;
}
//限定以表单提交的形式执行CGI程式,
否则将页面重定向到输入表单
if (strcmp(pRequestMethod,“POST") != 0){
cout < < “Location: /changePass.htm\n\n";
return;
}
PrintMIMEHeader();
PrintHTMLHeader();
GetPOSTData();
ProcessData();
if(wcscmp(NewPassword1,NewPassword2)== 0)
{
switch(ChangePassword()){
case NERR_Success:
cout < < “< center >
< h2 >成功更改用户密码。< /h2 >";
break;
case ERROR_ACCESS_DENIED:
cout < < “< center >< h2 >
密码更改失败:拒绝访问。< /h2 >";
break;
case ERROR_INVALID_PASSWORD:
cout < < “< center >< h2 >
密码更改失败:无效的密码。< /h2 >";
break;
case NERR_UserNotFound:
cout < < “< center >< h2 >
密码更改失败:不存在该用户。< /h2 >";
break;
case NERR_PasswordTooShort :
cout < < “< center >< h2 >密码更改失败:
新密码不合要求,请选择新的密码。< /h2 >";
break;
default:
cout < < “< center >< h2 >密码更改失败。< /h2 >";
}
}
else
cout < < “< center >< h2 >密码更改失败:
两次输入新口令不一致。< /h2 >";
PrintHTMLTrailer();
}