Webatrice: support hashed passwords in register and resetPassword (#4549)

* support hashed passwords in register and resetPassword

* lint

* support hashedPasswords for accountActivation

* use salt in post-register login step

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto 2022-01-30 22:09:16 -06:00 committed by GitHub
parent 92f941a54c
commit 992e28797f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 15 deletions

View file

@ -3,6 +3,7 @@ import { Room, StatusEnum, User, WebSocketConnectReason } from 'types';
import { SessionCommands } from '../commands';
import { RoomPersistence, SessionPersistence } from '../persistence';
import { ProtobufEvents } from '../services/ProtobufService';
import { passwordSaltSupported } from '../utils';
import webClient from '../WebClient';
export const SessionEvents: ProtobufEvents = {
@ -122,18 +123,25 @@ function serverIdentification(info: ServerIdentificationData) {
switch (webClient.options.reason) {
case WebSocketConnectReason.LOGIN:
SessionCommands.updateStatus(StatusEnum.LOGGING_IN, 'Logging In...');
// Intentional use of Bitwise operator b/c of how Servatrice Enums work
if (serverOptions & webClient.protobuf.controller.Event_ServerIdentification.ServerOptions.SupportsPasswordHash) {
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
} else {
SessionCommands.login();
}
break;
case WebSocketConnectReason.REGISTER:
SessionCommands.register();
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
} else {
SessionCommands.register();
}
break;
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
SessionCommands.activateAccount();
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
} else {
SessionCommands.activateAccount();
}
break;
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
SessionCommands.resetPasswordRequest();
@ -142,7 +150,11 @@ function serverIdentification(info: ServerIdentificationData) {
SessionCommands.resetPasswordChallenge();
break;
case WebSocketConnectReason.PASSWORD_RESET:
SessionCommands.resetPassword();
if (passwordSaltSupported(serverOptions, webClient)) {
SessionCommands.requestPasswordSalt();
} else {
SessionCommands.resetPassword();
}
break;
default:
SessionCommands.updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Reason: ' + webClient.options.reason);