Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
elixxir
xxdk-wasm
Commits
9f176d2a
Commit
9f176d2a
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Add VerifyPassword, which allows the checking if the password is correct
parent
d65c4208
No related branches found
No related tags found
1 merge request
!60
Revert "Fail a test to be sure it works"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
creds/password.go
+20
-8
20 additions, 8 deletions
creds/password.go
creds/password_test.go
+18
-0
18 additions, 0 deletions
creds/password_test.go
main.go
+1
-0
1 addition, 0 deletions
main.go
with
39 additions
and
8 deletions
creds/password.go
+
20
−
8
View file @
9f176d2a
...
...
@@ -116,15 +116,19 @@ func ChangeExternalPassword(_ js.Value, args []js.Value) interface{} {
return
nil
}
// getOrInit takes a user-provided password and returns its associated 256-bit
// internal password.
// VerifyPassword determines if the user-provided password is correct.
//
// If the internal password has not previously been created, then it is
// generated, saved to local storage, and returned. If the internal password has
// been previously generated, it is retrieved from local storage and returned.
// Parameters:
// - args[0] - The user supplied password (string).
//
// Any password saved to local storage is encrypted using the user-provided
// password.
// Returns:
// - True if the password is correct and false if it is incorrect (boolean).
func
VerifyPassword
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
return
verifyPassword
(
args
[
0
]
.
String
())
}
// getOrInit is the private function for GetOrInitPassword that is used for
// testing.
func
getOrInit
(
externalPassword
string
)
([]
byte
,
error
)
{
localStorage
:=
utils
.
GetLocalStorage
()
internalPassword
,
err
:=
getInternalPassword
(
externalPassword
,
localStorage
)
...
...
@@ -141,7 +145,8 @@ func getOrInit(externalPassword string) ([]byte, error) {
return
internalPassword
,
nil
}
// changeExternalPassword allows a user to change their external password.
// changeExternalPassword is the private function for ChangeExternalPassword
// that is used for testing.
func
changeExternalPassword
(
oldExternalPassword
,
newExternalPassword
string
)
error
{
localStorage
:=
utils
.
GetLocalStorage
()
internalPassword
,
err
:=
getInternalPassword
(
oldExternalPassword
,
localStorage
)
...
...
@@ -164,6 +169,13 @@ func changeExternalPassword(oldExternalPassword, newExternalPassword string) err
return
nil
}
// verifyPassword is the private function for VerifyPassword that is used for
// testing.
func
verifyPassword
(
externalPassword
string
)
bool
{
_
,
err
:=
getInternalPassword
(
externalPassword
,
utils
.
GetLocalStorage
())
return
err
==
nil
}
// initInternalPassword generates a new internal password, stores an encrypted
// version in local storage, and returns it.
func
initInternalPassword
(
externalPassword
string
,
...
...
This diff is collapsed.
Click to expand it.
creds/password_test.go
+
18
−
0
View file @
9f176d2a
...
...
@@ -75,6 +75,24 @@ func Test_changeExternalPassword(t *testing.T) {
}
}
// Tests that verifyPassword returns true for a valid password and false for an
// invalid password
func
Test_verifyPassword
(
t
*
testing
.
T
)
{
externalPassword
:=
"myPassword"
if
_
,
err
:=
getOrInit
(
externalPassword
);
err
!=
nil
{
t
.
Errorf
(
"%+v"
,
err
)
}
if
!
verifyPassword
(
externalPassword
)
{
t
.
Errorf
(
"Password %q is incorrect."
,
externalPassword
)
}
if
verifyPassword
(
"wrong password"
)
{
t
.
Error
(
"Incorrect password found to be correct."
)
}
}
// Tests that the internal password returned by initInternalPassword matches
// the encrypted one saved to local storage.
func
Test_initInternalPassword
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
main.go
+
1
−
0
View file @
9f176d2a
...
...
@@ -42,6 +42,7 @@ func main() {
js
.
Global
()
.
Set
(
"GetOrInitPassword"
,
js
.
FuncOf
(
creds
.
GetOrInitPassword
))
js
.
Global
()
.
Set
(
"ChangeExternalPassword"
,
js
.
FuncOf
(
creds
.
ChangeExternalPassword
))
js
.
Global
()
.
Set
(
"VerifyPassword"
,
js
.
FuncOf
(
creds
.
VerifyPassword
))
// utils/array.go
js
.
Global
()
.
Set
(
"Uint8ArrayToBase64"
,
js
.
FuncOf
(
utils
.
Uint8ArrayToBase64
))
...
...
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