sakto

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 9 Imported by: 4

README

sakto The sakto package is the simplified common input validators for your Go projects.

Installation

go get -u github.com/itrepablik/sakto

Usage

These are some of the examples on how you can use this package.

package main

import (
	"fmt"

	"github.com/itrepablik/itrlog"
	"github.com/itrepablik/sakto"
)

func main() {
	// These are some few examples that you can use for your Go project.
	// HashAndSalt usage: hash any plain text password
	plainTextPassword := "hEllo_World!"
	hsPassword, err := sakto.HashAndSalt([]byte(plainTextPassword))
	if err != nil {
		itrlog.Fatal(err)
	}
	fmt.Println("hsPassword: ", hsPassword)

	// CheckPasswordHash usage: compare the plain text password vs hashed password stored from your database.
	isPassHashMatch, err := sakto.CheckPasswordHash(plainTextPassword, hsPassword)
	if isPassHashMatch {
		fmt.Println("Password match, login successful!")
	} else {
		fmt.Println("Invalid password, please try again!")
	}
}

Subscribe to Maharlikans Code Youtube Channel:

Please consider subscribing to my Youtube Channel to recognize my work on this package. Thank you for your support! https://www.youtube.com/channel/UCdAVUmldU9Jn2VntuQChHqQ/

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) (bool, error)

CheckPasswordHash compares the two passwords between the stored hash and the raw plain text password.

func GetCurDT

func GetCurDT(t time.Time, timeZone string) time.Time

GetCurDT gets the current system date and time with specified local timezone, e.g timeZone = "Asia/Manila".

func GetIP

func GetIP(r *http.Request) string

GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.

func HashAndSalt

func HashAndSalt(pwd []byte) (string, error)

HashAndSalt is to hash user's password using bycrypt in Go.

func IsEmailValid

func IsEmailValid(email string) bool

IsEmailValid ensure the email is a valid email address.

func IsFileExist added in v1.0.4

func IsFileExist(filename string) bool

IsFileExist checks if the file existed or not

func IsURLValid

func IsURLValid(strURL string) bool

IsURLValid ensure that only a valid URL pattern will be accepted.

func IsUserNameValid

func IsUserNameValid(userName string) bool

IsUserNameValid ensure that only allowed special characters like @, ., +, -, and _.

func LocalNow added in v1.0.3

func LocalNow(tz string) time.Time

LocalNow gets the current local time with localize timezone

func ParseFloatToString added in v1.0.2

func ParseFloatToString(strInt string, bitSize, decimals int) (string, error)

ParseFloatToString parses any float value, options: bitSize either (32 or 64) with decimal value. Ideal for any pricing or financial amount values.

func TimeParseToString added in v1.0.2

func TimeParseToString(strDT, dateTimeFormat string) (string, error)

TimeParseToString parses the time.Time with specific date and time format.

func TrimQ added in v1.0.2

func TrimQ(cleanStr string) string

TrimQ removes the trailing double quotes ("") from a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL