用ASP為你的網站加密

來源:互聯網
上載者:User

標籤:style   blog   java   tar   ext   color   

用ASP為你的網站加密

正在學習建設web網站的讀者,可能正在為網站的安全性而擔憂;也許你正在建設一個非公開性網站,只有系統使用者才可以訪問你的網站。如果你編製的是ASP網頁,那麼你可以通過本文輕鬆達到這一目的。

首先,你需要製作登入頁面,在html中加入form,並設為自發送頁

〈form name=″login″ action=″default.ASP″ method=″post″ target=″—top″〉

action後接本頁url,這樣即使使用者登入錯誤,在本頁即獲提示,而無須再返回前一頁登入。在表單中加入

〈input name=″uid″ size=″10″maxlength=″10″ style=″height: 21px; width: 101px″〉

〈input name=″pwd″ type=″password″ size=″10″ maxlength=″10″〉


完成html後,在頁首填加程式碼如下:

〈% ′send customer direct to main page if already logged in

if not isempty(session(″cust—id″)) and len(session(″cust—id″))〉0 then response.redirect(″navigation/dashbrd.ASP″)

′在此添入你真正的首頁url

end if

′set flags

blogin = false

berror = false

′check blank entries

if isempty(request(″uid″)) or len(request(″uid″)) = 0 or isempty(request(″pwd″)) or len(request(″pwd″)) = 0 then

′need to log in

blogin = true

else

′check user credentials against db

… ′檢驗你的資料庫儲存密碼錶中是否有該使用者

′此處放入串連資料庫代碼

′其sql如下 ″select * from customer where cust—id=′ ″ & request(″uid″) & ″ ′ and ′cust—pwd=′ ″ & request(″pwd″) & ″ ′ ″

′其中request(″uid″)和request(″pwd″) 為本頁html中表單中的使用者名稱和密碼的text

gbfound = false

if not rscust.bof and not rscust.eof then

gbfound = true

end if

if gbfound then

′record useful customer info in session variables

session(″cust—id″) = rscust.fields(″cust—id″)

′ 此項為資料庫中使用者名稱

session(″cust—pwd″) = rscust.fields(″cust—pwd″) ′此項為資料庫中使用者密碼

session(″power″) = rscust.fields(″power″) ′此項為資料庫中使用者權限[可選]

′update last login time [可選]

′ rscust.activeconnection.execute (″update customer set cust—login = ′ ″& now & ″ ′ where cust_id = ″ & session(″cust—id″) & ″ ″)

response.redirect(″navigation/dashbrd.ASP″) ′真正首頁url

else

′uid and password not found

berror = true blogin = true

end if

rscust.close

′close recordset

mycn—login.close

set mycn—login=nothing

′get all policy numbers held by customer

end if

%〉

最後,你要做的就是在你的每一個頁面的開頭,加入以下代碼:

〈% if isempty(session(″cust—id″)) or len(trim(session(″cust—id″)) = 0 then %〉

〈script language=″javascript″ runat=client〉

〈!——

top.location.href = ″../default.ASP″

//——〉

〈script〉

〈% response.end

end if %〉


其中,session(″cust—id″) 為註冊的使用者名稱。

top.location.href = ″../default.ASP″ 將自動導航到你的登入介面。

在這樣處理之後,恭喜你,你的web網站就有了安全登入的功能。即使別人知道了你的網站的地址,在不進行合法登入的情況下,也無法訪問其他網頁。並且,在你的網頁逾時後,需要使用者重新登入,這樣即便操作者臨時離開,也不必擔心非法者的惡意操作。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.