@@ -147,25 +147,24 @@ function signup(userInput, passInput, passInput2, emailInput) {
147
147
password2 = passInput2 . value ,
148
148
email = emailInput . value ;
149
149
150
- // do any preprocessing on the user input here before sending to the server
150
+ // checking is done with HTML and functions at the end of the file
151
+ // hash password with username
152
+ digestMessage ( username + password ) . then ( digestValue => {
153
+ password = bufferToHexString ( digestValue ) ;
151
154
152
- // send the signup form to the server
153
- serverRequest ( "signup" , // resource to call
154
- {
155
+ // send the signup form to the server
156
+ serverRequest ( "signup" , {
155
157
"username" : username ,
156
158
"password" : password ,
157
159
"email" : email
158
- } // this should be populated with needed parameters
159
- ) . then ( function ( result ) {
160
- // if everything was good
161
- if ( result . response . ok ) {
162
- // do any work needed if the signup request succeeded
163
-
164
- // go to the login page
165
- showContent ( "login" ) ;
166
- }
167
- // show the status message from the server
168
- serverStatus ( result ) ;
160
+ } ) . then ( result => {
161
+ if ( result . response . ok ) {
162
+ // go to the login page
163
+ showContent ( "login" ) ;
164
+ }
165
+ // show the status message from the server
166
+ serverStatus ( result ) ;
167
+ } ) ;
169
168
} ) ;
170
169
}
171
170
@@ -328,3 +327,8 @@ function validateSignupInfo() {
328
327
329
328
return true ;
330
329
}
330
+
331
+ function digestMessage ( message ) {
332
+ const data = utf8ToUint8Array ( message ) ;
333
+ return window . crypto . subtle . digest ( 'SHA-256' , data ) ;
334
+ }
0 commit comments