Skip to content

Commit

Permalink
fix: password validation and auth and minor tweaks in code. removing …
Browse files Browse the repository at this point in the history
…fmt.Println statements.
  • Loading branch information
puni9869 committed May 21, 2024
1 parent 9abb8bc commit 47fedca
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var Version = cli.Command{
const version = "v1.0"

// versionAction prints the current version
func versionAction(ctx *cli.Context) error {
func versionAction(_ *cli.Context) error {
fmt.Println(version)
return nil
}
2 changes: 1 addition & 1 deletion config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"postgres": {
"type": "postgres",
"host": "127.0.0.1",
"username": "punitinani",
"username": "puni9869",
"password": "",
"port": "5432",
"databaseName": "pinmyblogs",
Expand Down
13 changes: 10 additions & 3 deletions models/session.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package models

import "gorm.io/gorm"
import (
"time"

"gorm.io/gorm"
)

// Session is gorm sessionstore shadow to properly delete the session
type Session struct {
gorm.Model
data string //lint:ignore U1000 Ignore unused function temporarily for debugging
ID string `gorm:"primarykey;size:65"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
data string //lint:ignore U1000 Ignore unused function temporarily for debugging
}
2 changes: 0 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"errors"
"fmt"

"github.com/spf13/viper"
)
Expand Down Expand Up @@ -85,7 +84,6 @@ func LoadConfig(environment string) error {
return err
}
err = viper.Unmarshal(&C)
fmt.Println(C)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions server/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"fmt"
"net/http"
"strings"

"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -35,12 +36,11 @@ func LoginPost(c *gin.Context) {
c.Abort()
return
}

h := sha256.New()
h.Write([]byte(password))
bs := h.Sum(nil)
pas := fmt.Sprintf("%x", bs)
fmt.Println(pas)
if fmt.Sprintf("%x", bs) != user.Password {
pass := fmt.Sprintf("%x", bs)
if strings.Compare(pass, user.Password) != 0 {
log.WithField("email", email).WithError(result.Error).Error("Invalid password.")
c.HTML(http.StatusUnauthorized, "login.tmpl", gin.H{"HasError": true, "Error": "Invalid email or password"})
c.Abort()
Expand Down

0 comments on commit 47fedca

Please sign in to comment.