2016-10-27 56 views
0
  1. 我有一個經典的asp網站,但我不是很擅長。有一個頁面,用戶可以更改他們的用戶名密碼。我想讓用戶只更改密碼,而不是用戶名。我對代碼做了一些修改,但沒有奏效。 的形式如下:old form

我想讓它像:new form在經典asp中更新密碼頁面

<% 
oldUsername=QS_CLEAR(request.QueryString("s1")) 
oldPassword=request.QueryString("s2") 
newUsername=QS_CLEAR(request.QueryString("nu")) 
newPassword=request.QueryString("np1") 
newComfirm=request.QueryString("np2") 
if oldUsername="" or oldPassword="" or newUsername="" or newPassword="" or newComfirm="" then 
    response.Write("<div id=""hata"">Fill the form correctly.</div>") 
elseif QS_CLEAR(newPassword)<>QS_CLEAR(newComfirm) then 
    response.Write("<div id=""hata"">New passwords do not match.</div>") 
else 
    rst.open "SELECT * FROM Users WHERE (Type='T') AND (username='"&username&"') and (UserID<>"&ID&")",conn,3,3 
    if rst.eof then 
     rst.close:rst.open "SELECT * FROM Users WHERE ID="&session("UserID"),conn,3,3 
     if lcase(rst("username"))<>lcase(oldUsername) then 
      response.Write("<div id=""hata"">Your username is wrong.</div>") 
     elseif encode(lcase(oldUsername)&oldPassword&lcase(mid(cstr(rst("GUID")),2,36)))<>rst("Password") then 
      response.Write("<div id=""hata"">Your password is wrong.</div>") 
     else 
      GUID=lcase(GetGuid()):password=encode(lcase(oldUsername)&newPassword&GUID) 
      rst("Username")=newUsername:rst("Password")=password:rst("GUID")="{"&GUID&"}" 
      rst.update 
      response.Write("<div id=""basarili"">Your password has changed.</div>") 
     end if 
    else 
     response.Write("<div id=""hata"">You can not choose this username.</div>") 
    end if 
    rst.close 
end if 

%> 

我應該在上面的代碼,以什麼樣的變化,使其工作。

  • 同時,我想補充的日期和密碼改爲在我的數據庫的用戶表PasswordChanged場時間。下面
  • +0

    「但它不工作」 < - 任何錯誤? – SearchAndResQ

    +0

    當我點擊更改按鈕時無動作 –

    +0

    它通過GUID進行操作 –

    回答

    0

    未經測試的代碼:

    增加了一些意見,請或詢問如果您需要更多的信息,如果有任何錯誤

    <% 
    'we have only three inputs now, 
    
    oldPassword=request.QueryString("s2") 
    newPassword=request.QueryString("np1") 
    newComfirm=request.QueryString("np2") 
    
    Response.write "oldPassword = " & oldPassword & "<br>"; 
    Response.write "newPassword = " & newPassword & "<br>"; 
    Response.write "newComfirm = " & newComfirm & "<br>"; 
    
    if oldPassword="" or newPassword="" or newComfirm="" then 
        response.Write("<div id=""hata"">Fill the form correctly.</div>") 
    elseif QS_CLEAR(newPassword)<>QS_CLEAR(newComfirm) then 
        response.Write("<div id=""hata"">New passwords do not match.</div>") 
    else 
        Dim sql : sql = "SELECT * FROM Users WHERE ID="&session("UserID") 
        Response.write "sql=" & sql & "<br>" 
        rst.open sql,conn,3,3 
        if NOT rst.EOF 
         'check if the old password provided is correct.Use rst("Username") instead of oldUsername 
         if encode(lcase(rst("Username"))&oldPassword&lcase(mid(cstr(rst("GUID")),2,36)))<>rst("Password") then 
          response.Write("<div id=""hata"">Your password is wrong.</div>") 
         else 
          GUID=lcase(GetGuid()) 
          password=encode(lcase(rst("Username")&newPassword&GUID) 
          rst("Password")=password 
          rst("GUID")="{"&GUID&"}" 
          'add changed date, may need some tweaking for the required format. 
          rst("PasswordChanged") = Now 
          rst.update 
          response.Write("<div id=""basarili"">Your password has changed.</div>") 
         end if 
        end if 
        rst.close 
    end if 
    
    %>