Reputation: 429
I need to hid a password.
I get (mismatched types []byte
and int
).
How can i fix it? How can I convert from int
to []byte
?
package main
import ("fmt"; "github.com/howeyc/gopass")
func main() {
var user string
maping := map[string]int{"dasha": 123, "mike": 777}
fmt.Println("Enter username: ")
fmt.Scan(&user)
fmt.Printf("Enter password: ")
pass, err := gopass.GetPasswd()
if err != nil {
return
}
if pass == maping[user] {
fmt.Println("bingo")
}else{
fmt.Println("the login or password is not correct")
}
}
Upvotes: 1
Views: 1612
Reputation: 3382
You can do the conversion with strconv
's Atoi()
function:
i, err := strconv.Atoi("-42")
And you'd convert your []byte
to a string
with
s := string(byteArray[:])
So the combination is
i, err := strconv.Atoi(string(pass[:]))
Upvotes: 2