英文:
buffering during authentication
问题
在这本关于使用Go构建Web应用程序的书籍中,它演示了如何创建自定义身份验证。注册功能的一部分使用了以下代码:
md5Password := md5.New()
io.WriteString(md5Password, password)
buffer := bytes.NewBuffer(nil)
fmt.Fprintf(buffer, "%x", md5Password.Sum(nil))
newPass := buffer.String()
这段代码基本上在登录功能中重复出现:
md5Password := md5.New()
io.WriteString(md5Password, password)
buffer := bytes.NewBuffer(nil)
fmt.Fprintf(buffer, "%x", md5Password.Sum(nil))
newPass := buffer.String()
在代码的最后四行中,缓冲区的作用是什么?为什么它很重要,缓冲如何实现这一目的?
英文:
In this book enter link description here on building web applications with Go, it demonstrates how to create custom authentication. Part of the registration function uses this code
md5Password := md5.New()
io.WriteString(md5Password, password)
buffer := bytes.NewBuffer(nil)
fmt.Fprintf(buffer, "%x", md5Password.Sum(nil))
newPass := buffer.String()
which is basically repeated in the login function
md5Password := md5.New()
io.WriteString(md5Password, password)
buffer := bytes.NewBuffer(nil)
fmt.Fprintf(buffer, "%x", md5Password.Sum(nil))
newPass := buffer.String()
What is happening with the buffering in the last 4 lines of the code? Why is it important and how does buffering achieve it?
答案1
得分: 0
我不确定这样做的目的是什么,但是可以用以下代码替换:
md5Password := md5.New()
io.WriteString(md5Password, password)
newPass := fmt.Sprintf("%x", md5Password.Sum(nil))
原始的书可能已经过时了,但是没有必要进行额外的 bytes.Buffer
步骤。
英文:
I'm not sure what's the point of that, however that can be replaced by :
md5Password := md5.New()
io.WriteString(md5Password, password)
newPass := fmt.Sprintf("%x", md5Password.Sum(nil))
The original book might be outdated, but there's absolutely no need for that extra bytes.Buffer
step.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论