2021-11-10 01:44:22 +00:00
|
|
|
package internal
|
2021-11-08 10:04:01 +00:00
|
|
|
|
2021-11-09 04:48:24 +00:00
|
|
|
import (
|
2021-11-09 05:26:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Selly-Modules/mongodb"
|
2021-11-09 04:48:24 +00:00
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
)
|
2021-11-08 10:04:01 +00:00
|
|
|
|
2021-11-10 01:44:22 +00:00
|
|
|
func HashPassword(password string) string {
|
2021-11-08 10:04:01 +00:00
|
|
|
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), passwordHashingCost)
|
|
|
|
return string(bytes)
|
|
|
|
}
|
|
|
|
|
2021-11-10 01:44:22 +00:00
|
|
|
func CheckPasswordHash(password, hash string) bool {
|
2021-11-08 10:04:01 +00:00
|
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
|
|
return err == nil
|
|
|
|
}
|
2021-11-09 05:26:51 +00:00
|
|
|
|
2021-11-10 01:44:22 +00:00
|
|
|
func GetSearchString(fieldList ...string) string {
|
2021-11-09 05:26:51 +00:00
|
|
|
var (
|
|
|
|
searchList = make([]interface{}, 0)
|
|
|
|
format = ""
|
|
|
|
)
|
|
|
|
|
|
|
|
for i, value := range fieldList {
|
|
|
|
searchList = append(searchList, mongodb.NonAccentVietnamese(value))
|
|
|
|
if i == 0 {
|
|
|
|
format += "%s"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
format += " %s"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf(format, searchList...)
|
|
|
|
}
|