本文整理汇总了Golang中github.com/xyproto/pinterface.IUserState.PasswordHash方法的典型用法代码示例。如果您正苦于以下问题:Golang IUserState.PasswordHash方法的具体用法?Golang IUserState.PasswordHash怎么用?Golang IUserState.PasswordHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xyproto/pinterface.IUserState
的用法示例。
在下文中一共展示了IUserState.PasswordHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenerateAdminStatus
// TODO: Log and graph when people visit pages and when people contribute content
// This one is wrapped by ServeAdminPages
func GenerateAdminStatus(state pinterface.IUserState) SimpleContextHandle {
return func(ctx *web.Context) string {
if !state.AdminRights(ctx.Request) {
return "<div class=\"no\">Not logged in as Administrator</div>"
}
// TODO: List all sorts of info, edit users, etc
s := "<h2>Administrator Dashboard</h2>"
s += "<strong>User table</strong><br />"
s += "<table class=\"whitebg\">"
s += "<tr>"
s += "<th>Username</th><th>Confirmed</th><th>Logged in</th><th>Administrator</th><th>Admin toggle</th><th>Remove user</th><th>Email</th><th>Password hash</th>"
s += "</tr>"
usernames, err := state.AllUsernames()
if err == nil {
for rownr, username := range usernames {
if rownr%2 == 0 {
s += "<tr class=\"even\">"
} else {
s += "<tr class=\"odd\">"
}
s += "<td><a class=\"username\" href=\"/status/" + username + "\">" + username + "</a></td>"
s += TableCell(state.IsConfirmed(username))
s += TableCell(state.IsLoggedIn(username))
s += TableCell(state.IsAdmin(username))
s += "<td><a class=\"darkgrey\" href=\"/admintoggle/" + username + "\">admin toggle</a></td>"
// TODO: Ask for confirmation first with a MessageOKurl("blabla", "blabla", "/actually/remove/stuff")
s += "<td><a class=\"careful\" href=\"/remove/" + username + "\">remove</a></td>"
email, err := state.Email(username)
if err == nil {
// The cleanup happens at registration time, but it's ok with an extra cleanup
s += "<td>" + CleanUserInput(email) + "</td>"
}
passwordHash, err := state.PasswordHash(username)
if err == nil {
if strings.HasPrefix(passwordHash, "abc123") {
s += "<td>" + passwordHash + " (<a href=\"/fixpassword/" + username + "\">fix</a>)</td>"
} else {
s += "<td>" + symbolhash.New(passwordHash, 16).String() + "</td>"
}
}
s += "</tr>"
}
}
s += "</table>"
s += "<br />"
s += "<strong>Unconfirmed users</strong><br />"
s += "<table>"
s += "<tr>"
s += "<th>Username</th><th>Confirmation link</th><th>Remove</th>"
s += "</tr>"
usernames, err = state.AllUnconfirmedUsernames()
if err == nil {
for _, username := range usernames {
s += "<tr>"
s += "<td><a class=\"username\" href=\"/status/" + username + "\">" + username + "</a></td>"
confirmationCode, err := state.ConfirmationCode(username)
if err != nil {
panic("ERROR: Could not get confirmation code")
}
s += "<td><a class=\"somewhatcareful\" href=\"/confirm/" + confirmationCode + "\">" + confirmationCode + "</a></td>"
s += "<td><a class=\"careful\" href=\"/removeunconfirmed/" + username + "\">remove</a></td>"
s += "</tr>"
}
}
s += "</table>"
return s
}
}
示例2: exportUserstate
//.........这里部分代码省略.........
L.SetGlobal("ClearCookie", L.NewFunction(func(L *lua.LState) int {
userstate.ClearCookie(w)
return 0 // number of results
}))
// Get the username stored in a cookie, or an empty string
// Takes no arguments
L.SetGlobal("AllUsernames", L.NewFunction(func(L *lua.LState) int {
usernames, err := userstate.AllUsernames()
var table *lua.LTable
if err != nil {
table = L.NewTable()
} else {
table = strings2table(L, usernames)
}
L.Push(table)
return 1 // number of results
}))
// Get the email for a given username, or an empty string
// Takes a username
L.SetGlobal("Email", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
email, err := userstate.Email(username)
var result lua.LString
if err != nil {
result = lua.LString("")
} else {
result = lua.LString(email)
}
L.Push(result)
return 1 // number of results
}))
// Get the password hash for a given username, or an empty string
// Takes a username
L.SetGlobal("PasswordHash", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
pw, err := userstate.PasswordHash(username)
var result lua.LString
if err != nil {
result = lua.LString("")
} else {
result = lua.LString(pw)
}
L.Push(result)
return 1 // number of results
}))
// Get all unconfirmed usernames
// Takes no arguments
L.SetGlobal("AllUnconfirmedUsernames", L.NewFunction(func(L *lua.LState) int {
usernames, err := userstate.AllUnconfirmedUsernames()
var table *lua.LTable
if err != nil {
table = L.NewTable()
} else {
table = strings2table(L, usernames)
}
L.Push(table)
return 1 // number of results
}))
// Get a confirmation code that can be given to a user, or an empty string
// Takes a username
L.SetGlobal("ConfirmationCode", L.NewFunction(func(L *lua.LState) int {
username := L.ToString(1)
pw, err := userstate.ConfirmationCode(username)
var result lua.LString
if err != nil {
result = lua.LString("")