本文整理汇总了Golang中github.com/astaxie/beego/utils.RandomCreateBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang RandomCreateBytes函数的具体用法?Golang RandomCreateBytes怎么用?Golang RandomCreateBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomCreateBytes函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Profile
// 个人信息
func (this *MainController) Profile() {
beego.ReadFromRequest(&this.Controller)
user, _ := models.UserGetById(this.userId)
if this.isPost() {
flash := beego.NewFlash()
user.Email = this.GetString("email")
user.Update()
password1 := this.GetString("password1")
password2 := this.GetString("password2")
if password1 != "" {
if len(password1) < 6 {
flash.Error("密码长度必须大于6位")
flash.Store(&this.Controller)
this.redirect(beego.URLFor(".Profile"))
} else if password2 != password1 {
flash.Error("两次输入的密码不一致")
flash.Store(&this.Controller)
this.redirect(beego.URLFor(".Profile"))
} else {
user.Salt = string(utils.RandomCreateBytes(10))
user.Password = libs.Md5([]byte(password1 + user.Salt))
user.Update()
}
}
flash.Success("修改成功!")
flash.Store(&this.Controller)
this.redirect(beego.URLFor(".Profile"))
}
this.Data["pageTitle"] = "个人信息"
this.Data["user"] = user
this.display()
}
开发者ID:avldya,项目名称:webcron,代码行数:35,代码来源:main.go
示例2: generateRandomKey
// generateRandomKey creates a random key with the given strength.
func generateRandomKey(strength int) []byte {
k := make([]byte, strength)
if n, err := io.ReadFull(rand.Reader, k); n != strength || err != nil {
return utils.RandomCreateBytes(strength)
}
return k
}
开发者ID:horryq,项目名称:beego,代码行数:8,代码来源:sess_utils.go
示例3: BenchmarkNewImage
func BenchmarkNewImage(b *testing.B) {
b.StopTimer()
d := utils.RandomCreateBytes(challengeNums, defaultChars...)
b.StartTimer()
for i := 0; i < b.N; i++ {
NewImage(d, stdWidth, stdHeight)
}
}
开发者ID:happyluo,项目名称:beego,代码行数:8,代码来源:image_test.go
示例4: XsrfToken
// XsrfToken creates a xsrf token string and returns.
func (ctx *Context) XsrfToken(key string, expire int64) string {
if ctx._xsrf_token == "" {
token, ok := ctx.GetSecureCookie(key, "_xsrf")
if !ok {
token = string(utils.RandomCreateBytes(32))
ctx.SetSecureCookie(key, "_xsrf", token, expire)
}
ctx._xsrf_token = token
}
return ctx._xsrf_token
}
开发者ID:JiYou,项目名称:beego,代码行数:12,代码来源:context.go
示例5: BenchmarkImageWriteTo
func BenchmarkImageWriteTo(b *testing.B) {
b.StopTimer()
d := utils.RandomCreateBytes(challengeNums, defaultChars...)
b.StartTimer()
counter := &byteCounter{}
for i := 0; i < b.N; i++ {
img := NewImage(d, stdWidth, stdHeight)
img.WriteTo(counter)
b.SetBytes(counter.n)
counter.n = 0
}
}
开发者ID:happyluo,项目名称:beego,代码行数:12,代码来源:image_test.go
示例6: CreateCaptcha
// CreateCaptcha create a new captcha id
func (c *Captcha) CreateCaptcha() (string, error) {
// generate captcha id
id := string(utils.RandomCreateBytes(15))
// get the captcha chars
chars := c.genRandChars()
// save to store
if err := c.store.Put(c.key(id), chars, c.Expiration); err != nil {
return "", err
}
return id, nil
}
开发者ID:kingljl,项目名称:beego,代码行数:15,代码来源:captcha.go
示例7: CreateToken
func CreateToken(userId string) (string, error) {
token := Token{}
token.UserId = userId
token.Secret = string(utils.RandomCreateBytes(20))
token.Time = strconv.FormatInt(time.Now().UnixNano(), 10)
tokenByte, _ := json.Marshal(&token)
tokenStr := base64.URLEncoding.EncodeToString(tokenByte)
_, err := RedisStorageInstance.SetExpireKey(tokenStr, tokenStr, tokenExpireTIme)
if err != nil {
fmt.Println("redis操作失败" + err.Error())
return "", err
}
return tokenStr, nil
}
开发者ID:EPICPaaS,项目名称:account,代码行数:14,代码来源:token.go
示例8: XsrfToken
// XsrfToken creates a xsrf token string and returns.
func (c *Controller) XsrfToken() string {
if c._xsrf_token == "" {
token, ok := c.GetSecureCookie(XSRFKEY, "_xsrf")
if !ok {
var expire int64
if c.XSRFExpire > 0 {
expire = int64(c.XSRFExpire)
} else {
expire = int64(XSRFExpire)
}
token = string(utils.RandomCreateBytes(32))
c.SetSecureCookie(XSRFKEY, "_xsrf", token, expire)
}
c._xsrf_token = token
}
return c._xsrf_token
}
开发者ID:4eek,项目名称:beego,代码行数:18,代码来源:controller.go
示例9: getWebSocketsToken
///////////////////////////////////////////////////////
// getWebSocketsToken function
func (c *RootController) getWebSocketsToken() string {
if token := c.GetSession("WebSocketsToken"); token != nil {
return token.(string)
}
token := string(utils.RandomCreateBytes(32))
SessionXsrfTable.Lock()
defer SessionXsrfTable.Unlock()
s := c.StartSession()
SessionXsrfTable.Tokens[token] = SessionXsrfStruct{
Session: &s,
Timestamp: time.Now(),
}
c.SetSession("WebSocketsToken", token)
return token
}
开发者ID:lafisrap,项目名称:Computer-Spielplatz,代码行数:22,代码来源:controllers.go
示例10: createState
// create oauth2 state string
func (this *SocialAuth) createState(ctx *context.Context, social SocialType) string {
values := make(url.Values, 2)
if uid, ok := this.app.IsUserLogin(ctx); ok {
// add uid if user current is login
values.Add("uid", strconv.FormatInt(int64(uid), 10))
}
// our secret string
values.Add("secret", string(utils.RandomCreateBytes(20)))
// create state string
state := base64.URLEncoding.EncodeToString([]byte(values.Encode()))
// save to session
name := this.getSessKey(social, "state")
ctx.Input.CruSession.Set(name, state)
return state
}
开发者ID:naokij,项目名称:social-auth,代码行数:21,代码来源:social.go
示例11: sessionId
// generate session id with rand string, unix nano time, remote addr by hash function.
func (manager *Manager) sessionId(r *http.Request) (sid string) {
bs := make([]byte, 32)
if n, err := io.ReadFull(rand.Reader, bs); n != 32 || err != nil {
bs = utils.RandomCreateBytes(32)
}
sig := fmt.Sprintf("%s%d%s", r.RemoteAddr, time.Now().UnixNano(), bs)
if manager.config.SessionIDHashFunc == "md5" {
h := md5.New()
h.Write([]byte(sig))
sid = hex.EncodeToString(h.Sum(nil))
} else if manager.config.SessionIDHashFunc == "sha1" {
h := hmac.New(sha1.New, []byte(manager.config.SessionIDHashKey))
fmt.Fprintf(h, "%s", sig)
sid = hex.EncodeToString(h.Sum(nil))
} else {
h := hmac.New(sha1.New, []byte(manager.config.SessionIDHashKey))
fmt.Fprintf(h, "%s", sig)
sid = hex.EncodeToString(h.Sum(nil))
}
return
}
开发者ID:4eek,项目名称:beego,代码行数:22,代码来源:session.go
示例12: genRandChars
// generate rand chars with default chars
func (c *Captcha) genRandChars() []byte {
return utils.RandomCreateBytes(c.ChallengeNums, defaultChars...)
}
开发者ID:kingljl,项目名称:beego,代码行数:4,代码来源:captcha.go
注:本文中的github.com/astaxie/beego/utils.RandomCreateBytes函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论