Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
10de62da
Commit
10de62da
authored
1 year ago
by
Francé Wilke
Browse files
Options
Downloads
Patches
Plain Diff
Put used function back
parent
387dd298
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
auth/common.go
+24
-0
24 additions, 0 deletions
auth/common.go
auth/words.go
+104
-0
104 additions, 0 deletions
auth/words.go
with
128 additions
and
0 deletions
auth/common.go
+
24
−
0
View file @
10de62da
package
auth
import
(
"fmt"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/handler_utils"
"golang.org/x/crypto/bcrypt"
"math/rand"
"strings"
)
...
...
@@ -30,3 +32,25 @@ func PasswordIsCorrect(password string, hashedPassword string) bool {
err
:=
bcrypt
.
CompareHashAndPassword
([]
byte
(
hashedPassword
),
[]
byte
(
password
))
return
err
==
nil
}
// Create a pseudorandom password consisting of two three-letter words and two digits
func
RandomPassword
()
string
{
i
:=
rand
.
Intn
(
100
)
var
j
int
for
{
j
=
rand
.
Intn
(
100
)
if
j
!=
i
{
break
}
}
return
fmt
.
Sprintf
(
"%s%s%s"
,
words
[
i
],
words
[
j
],
RandomDigitString
(
2
))
}
// Create a pseudorandom string of digits (0-9) with specified length
func
RandomDigitString
(
len
int
)
string
{
var
str
strings
.
Builder
for
i
:=
0
;
i
<
len
;
i
++
{
fmt
.
Fprintf
(
&
str
,
"%v"
,
rand
.
Intn
(
10
))
}
return
str
.
String
()
}
This diff is collapsed.
Click to expand it.
auth/words.go
0 → 100644
+
104
−
0
View file @
10de62da
package
auth
var
words
=
[]
string
{
"act"
,
"add"
,
"age"
,
"air"
,
"ant"
,
"ark"
,
"arm"
,
"art"
,
"ash"
,
"bad"
,
"bag"
,
"bar"
,
"bat"
,
"bay"
,
"bed"
,
"bee"
,
"big"
,
"box"
,
"bus"
,
"bye"
,
"can"
,
"car"
,
"cat"
,
"con"
,
"cow"
,
"cup"
,
"day"
,
"dog"
,
"ear"
,
"end"
,
"eye"
,
"far"
,
"fly"
,
"fox"
,
"fry"
,
"fun"
,
"gap"
,
"gym"
,
"hat"
,
"hip"
,
"hop"
,
"ice"
,
"ink"
,
"jam"
,
"jar"
,
"joy"
,
"key"
,
"kit"
,
"lab"
,
"law"
,
"log"
,
"low"
,
"man"
,
"max"
,
"may"
,
"net"
,
"nut"
,
"oil"
,
"one"
,
"out"
,
"owl"
,
"own"
,
"pen"
,
"pet"
,
"pie"
,
"pig"
,
"pin"
,
"pro"
,
"ram"
,
"rap"
,
"ray"
,
"red"
,
"row"
,
"sea"
,
"see"
,
"sew"
,
"sit"
,
"six"
,
"sky"
,
"son"
,
"spy"
,
"tan"
,
"tax"
,
"tea"
,
"ted"
,
"tee"
,
"ten"
,
"the"
,
"tin"
,
"toe"
,
"top"
,
"toy"
,
"tub"
,
"two"
,
"way"
,
"wig"
,
"yes"
,
"you"
,
"zip"
,
"zoo"
,
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment