Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. func login(w http.ResponseWriter, r *http.Request) {
  2. var hashedPassword string
  3. var username = r.PostFormValue("username")
  4. var password = r.PostFormValue("password")
  5.  
  6. if username == "" || password == "" {
  7. fmt.Fprint(w, "Você precisa enviar os dados")
  8. return
  9. }
  10.  
  11. err := db.QueryRow("SELECT `senha` FROM login WHERE usuario = ? LIMIT 1", username).Scan(&hashedPassword)
  12. if err != nil {
  13. fmt.Fprint(w, "Senha ou usuário incorreto")
  14. return
  15. }
  16.  
  17. if err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)); err != nil {
  18. fmt.Fprint(w, "Senha ou usuário incorreto")
  19. return
  20. }
  21.  
  22. fmt.Fprint(w, "Conectado com sucesso")
  23. }
  24.  
  25. curl -d "username=QueNaoExiste&password=a" http://127.0.0.1:8888/login -w " "%{time_total}
  26.  
  27. curl -d "username=QueExiste&password=a" http://127.0.0.1:8888/login -w " "%{time_total}
  28.  
  29. curl -d "username=QueExiste&password=umasenhamuitolouca" http://127.0.0.1:8888/login -w " "%{time_total}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement