Skip to content

Commit

Permalink
hashing password corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomog committed Jan 2, 2024
1 parent 29bb00b commit 4f8c649
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/handler/githubhandler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package handler

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand All @@ -17,7 +19,6 @@ import (

"github.com/Pomog/ForumFFF/internal/models"
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
)

func (m *Repository) LoginWithGitHubHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -72,7 +73,8 @@ func (m *Repository) CallbackGitHubHandler(w http.ResponseWriter, r *http.Reques
fmt.Println("Failed to check User: ", err)
return
}
if userExist {
fmt.Println("userExist ", userExist)
if !userExist {
err := m.DB.CreateUser(user)
if err != nil {
fmt.Println("Failed to create User based on GitHub Data: ", err)
Expand Down Expand Up @@ -257,14 +259,13 @@ func processAvatarURL(url string, username string) (string, error) {
}

func generatePassword(email string) (string, error) {
// Use the email as a seed or input
// Use the email as input
password := []byte(email)

// Hash the password using bcrypt
hashedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
if err != nil {
return "", err
}
// Hash the password using sha256
hasher := sha256.New()
hasher.Write(password)
hashedPassword := hex.EncodeToString(hasher.Sum(nil))

return string(hashedPassword), nil
return hashedPassword, nil
}
2 changes: 2 additions & 0 deletions internal/handler/staticHelperHendlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"fmt"
"log"
"net/http"
"strconv"
Expand Down Expand Up @@ -90,6 +91,7 @@ func (m *Repository) PrivatPolicyHandler(w http.ResponseWriter, r *http.Request)
func (m *Repository) PersonaCabinetHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
userID, _ := strconv.Atoi(r.URL.Query().Get("userID"))
fmt.Println("userID ", userID)
var personalInfo models.User
user, errUser := m.DB.GetUserByID(userID)
if errUser != nil {
Expand Down
Binary file modified mainDB.db
Binary file not shown.

0 comments on commit 4f8c649

Please sign in to comment.