You've already forked openaccounting-server
mirror of
https://github.com/openaccounting/oa-server.git
synced 2025-12-09 00:50:59 +13:00
initial commit
This commit is contained in:
26
core/util/bcrypt.go
Normal file
26
core/util/bcrypt.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type Bcrypt interface {
|
||||
GenerateFromPassword([]byte, int) ([]byte, error)
|
||||
CompareHashAndPassword([]byte, []byte) error
|
||||
GetDefaultCost() int
|
||||
}
|
||||
|
||||
type StandardBcrypt struct {
|
||||
}
|
||||
|
||||
func (bc *StandardBcrypt) GenerateFromPassword(password []byte, cost int) ([]byte, error) {
|
||||
return bcrypt.GenerateFromPassword(password, cost)
|
||||
}
|
||||
|
||||
func (bc *StandardBcrypt) CompareHashAndPassword(hashedPassword, password []byte) error {
|
||||
return bcrypt.CompareHashAndPassword(hashedPassword, password)
|
||||
}
|
||||
|
||||
func (bc *StandardBcrypt) GetDefaultCost() int {
|
||||
return bcrypt.DefaultCost
|
||||
}
|
||||
46
core/util/util.go
Normal file
46
core/util/util.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Round64(input float64) int64 {
|
||||
if input < 0 {
|
||||
return int64(input - 0.5)
|
||||
}
|
||||
return int64(input + 0.5)
|
||||
}
|
||||
|
||||
func TimeToMs(date time.Time) int64 {
|
||||
return date.UnixNano() / 1000000
|
||||
}
|
||||
|
||||
func MsToTime(ms int64) time.Time {
|
||||
return time.Unix(0, ms*1000000)
|
||||
}
|
||||
|
||||
func NewGuid() (string, error) {
|
||||
byteArray := make([]byte, 16)
|
||||
|
||||
_, err := rand.Read(byteArray)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return hex.EncodeToString(byteArray), nil
|
||||
}
|
||||
|
||||
func NewInviteId() (string, error) {
|
||||
byteArray := make([]byte, 4)
|
||||
|
||||
_, err := rand.Read(byteArray)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return hex.EncodeToString(byteArray), nil
|
||||
}
|
||||
Reference in New Issue
Block a user