0
func (this *AdminModel) Login(v_name string, v_pwd string) (bool, error, uint) {
    o := orm.NewOrm()
    v_pwd_encrypt_byte := md5.Sum([]byte(v_pwd))
    v_pwd_encrypt := string(v_pwd_encrypt_byte[:])
    t_admin := Admin{Name: v_name, Pwd: v_pwd_encrypt}
    fmt.Printf("username:%v  password:%v\n", v_name, v_pwd_encrypt_byte)
    fmt.Printf("username:%v  password:%v\n", v_name, v_pwd_encrypt_byte[:])
    fmt.Printf("username:%v  password:%v\n", v_name, v_pwd_encrypt)
    err := o.Read(&t_admin, "Name", "Pwd")
    if err != nil {
        return false, err, 0
    } else {
        return true, nil, t_admin.Id
    }
}

print result:

username:yuhaya  password:[97 22 175 237 203 11 195 16 131 147 92 28 38 47 244 201]
username:yuhaya  password:[97 22 175 237 203 11 195 16 131 147 92 28 38 47 244 201]
username:yuhaya  password:a???
                          ???\&/??

Why the last line of the printing results gibberish?

v_pwd_encrypt := string(v_pwd_encrypt_byte[:])

Is this position convert out of the question?

1

2 Answers 2

2

Adding to @Ainar-G's answer, hex.EncodeToString is the most efficient way to do it since it doesn't involve reflection or type guessing like fmt.Sprintf.

func main() {
    sum := md5.Sum([]byte("meh"))
    stringSum := hex.EncodeToString(sum[:])
    fmt.Println(stringSum)
}
Sign up to request clarification or add additional context in comments.

Comments

1

md5.Sum() returns bytes, not printable ASCII characters. If you want to see hex representation of those bytes, you can use fmt.Sprintf("%x", ...), like this:

v_pwd_encrypt := fmt.Sprintf("%x", v_pwd_encrypt_byte)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.