使用者註冊主要有2個方法,1、密碼加密 2、使用者註冊 3、asp.net core identity 使用密碼策略、鎖定和 cookie 配置等設定的預設值。 可以在類中重寫這些設定startup(官方詳情點這裡)
首先建立createuserviewmodel檢視模型
using建立regiseter方法system.componentmodel;
using
system.componentmodel.dataannotations;
namespace
shop.viewmodel
[emailaddress(errormessage = "
郵箱格式不正確")]
[displayname("郵箱
")]public
string email
[displayname(
"手機號")]
[minlength(
11,errormessage = "
手機位數不足11位
"), stringlength(11
)]
public
string phonenumber
[required(errormessage = "
密碼不能為空")]
[datatype(datatype.password)]
[displayname("密碼
")]public
string passwordhash }}
public建立register檢視iactionresult register()
@model shop.viewmodel.createuserviewmodel建立register post方法@<
h1>register
h1>
<
form
class
="form-horizontal"
asp-action
="register"
method
="post"
>
<
div
asp-validation-summary
="modelonly"
class
="text-danger"
>
div>
<
fieldset
>
<
div
class
="control-group"
>
<
label
class
="control-label"
>使用者名稱
label
>
<
div
class
="controls"
>
<
input
type
="text"
placeholder
=""class
="input-xlarge"
asp-for
="username"
>
<
span
asp-validation-for
="username"
class
="text-danger"
>
span
>
div>
div>
<
div
class
="control-group"
>
<
label
class
="control-label"
>郵箱
label
>
<
div
class
="controls"
>
<
input
type
="text"
placeholder
=""class
="input-xlarge"
asp-for
="email"
>
<
span
asp-validation-for
="email"
class
="text-danger"
>
span
>
div>
div>
<
div
class
="control-group"
>
<
label
class
="control-label"
>手機號
label
>
<
div
class
="controls"
>
<
input
type
="text"
placeholder
=""class
="input-xlarge"
asp-for
="phonenumber"
>
<
span
asp-validation-for
="phonenumber"
class
="text-danger"
>
span
>
div>
div>
<
div
class
="control-group"
>
<
label
class
="control-label"
>密碼
label
>
<
div
class
="controls"
>
<
input
type
="text"
placeholder
=""class
="input-xlarge"
asp-for
="passwordhash"
>
<
span
asp-validation-for
="passwordhash"
class
="text-danger"
>
span
>
div>
div>
<
input
type
="submit"
class
="btn btn-primary"
value
="註冊"
>
fieldset
>
form
>
@*輸入內容跟模型定義規則不符時需要驗證提示加入此指令碼*@
@section scripts
}
//建立使用者
var result = await
_usermanager.createasync(user);
//如果成功則返回使用者列表
if(result.succeeded)
}return
view(input);
}效果展示,如果驗證錯誤則有如下提示
如果成功提交則返回使用者列表頁,注意:未做編號自增及使用者名稱是否重複的驗證
Identity使用者管理入門四(修改 刪除使用者)
修改使用者不能修改id及使用者名稱所以建立檢視模型時需要去除,新增使用者跟修改使用者基本檢視一直,所以不再做演示 一 新建updateuserviewmodel檢視模型 using system.componentmodel using system.componentmodel.dataannot...
oracle使用者管理入門
1.建立乙個新使用者 普通 create user username identified by password 演示樣例,建立乙個名叫小明的使用者,password為xm 2.以管理員的身份給普通使用者改動password 當普通使用者忘掉自己的password時 alter user user...
MySQL之使用者管理入門
1.多使用者資料庫 我們知道mysql是乙個多使用者資料庫,按使用者種類分類的話可以分為 root使用者 超級管理員,擁有所有許可權 普通使用者 被root使用者建立的使用者,它的許可權被root授予 2.什麼是使用者管理?簡單來說,就是root使用者管理普通使用者的訪問許可權和資訊以及管理root...