步步為營 85 註冊資訊驗證

2022-08-14 20:42:08 字數 3203 閱讀 2121

註冊資訊驗證:

1 前台驗證(js+ajax):

首先像"郵箱格式","非空"驗證可以通過js+正規表示式來完成;

另外像"使用者名稱是否存在","郵箱是否已使用"可通過 ajax向後台頁面發請求,實現無頁面重新整理的驗證()

2 僅僅是前台驗證會存在一定的安全隱患,所以當使用者提交時候還要實現後台驗證

使用者註冊表單

前端js驗證

注意 驗證"郵箱"的時候有一句

$.post("/ashx/validatereg.ashx", , function (data) );

using

bookshopmanager.web.common;

using

system;

using

system.collections.generic;

using

system.web;

using

system.web.sessionstate;

namespace

bookshopmanager.web.ashx

else

if (action == "

code")

else

}else

if (action == "

name")

else}}

#region 校驗郵箱

另外當點選"註冊"按鈕後,將表單元素序列化為json陣列物件

var par = $("#aspnetform").serializearray();                

par = json.stringify(par);

$.post("/ashx/userregister.ashx", , function (data) );

需要在後台引用 命名空間來實現反序列化

using newtonsoft.json;

using newtonsoft.json.linq;

jarray ja = (jarray)jsonconvert.deserializeobject(jsonstr);//反序列化

using

system;

using

system.collections.generic;

using

system.web;

using

system.io;

using

system.runtime.serialization.formatters.binary;

using

system.text;

using

system.servicemodel;

using

system.servicemodel.web;

using

system.runtime.serialization;

using

system.runtime.serialization.json;

using

system.web.script.serialization;

using

newtonsoft.json;

using

newtonsoft.json.linq;

using

bookshopmanager.web.common;

using

bookshopmanager.bll;

using

system.web.sessionstate;

using

bookshopmanager.web.enum;

using

system.web.ui;

namespace

bookshopmanager.web.ashx

else

}else

}private

bool validateuserinfo(string jsonstr,out

string msg, out

model.users userinfo)

if (string

.isnullorempty(userinfo.name))

if (string

.isnullorempty(userinfo.loginpwd))

if (string

.isnullorempty(confirmpwd))

if (string

.isnullorempty(userinfo.address))

if (string

.isnullorempty(userinfo.phone))

if (string

.isnullorempty(userinfo.mail))

if (string

.isnullorempty(validate))

if (msg.length > 1

)

//判斷密碼是否一致

if (userinfo.loginpwd !=confirmpwd)

//校驗驗證碼是否正確

if (!validatecode.checkvalidatecode(validate))

//校驗郵箱是否已使用,

if(usermanager.existsbyusermail(userinfo.mail))

//使用者名稱是否存在

}

註冊按鈕後校驗

步步為營 79 快取

快取cache,一種空間換取時間的技術,適用於經常訪問,不常修改的資料.1 寫入快取 1.1 方法一 cache message ab 1.2 方法二 cache.insert message ab 1.3 其他過載 insert string key,object value,cachedepen...

步步為營 50 事務

說明 比較常用 1 事務的四大特性 1.1 原子性atomicity 乙個事務中包含的多個sql語句,要麼同時成功,要麼同時失敗.1.2 一致性consistency 事務必須使資料庫從從乙個一致性狀態變成另外乙個一致性狀態.銀行轉賬 1.3 隔離性 isolation 各個事務執行互不干擾 鎖 1...

io nio socket步步為營(三)NIO

原理 運用reactor模式 selector是核心 分發器a multiplexor of selectablechannel objects。能檢測任意個註冊過的channel上的事件,並分發事件,內部實現不用考慮,封裝的好處。client沒必要用nio,使用中的client server,需要...