Ejemplo n.º 1
0
        private object OnHasPasswords( object message )
        {
            var packet = ( CreateAuthSessionKeyMessage )message;
            var ret = new OperationResult();

            PasswordManager passwordManager = new PasswordManager();

            ret.Value = passwordManager.HasPasswords();
            return ret;
        }
Ejemplo n.º 2
0
        private object OnDeletePassword( object message )
        {
            var packet = ( DeletePasswordMessage )message;
            var ret = new OperationResult();

            if ( !this.CheckSession( packet.SessionKey ) )
            {
                ret.Value = false;
                return ret;
            }

            PasswordManager passwordManager = new PasswordManager();

            string password = HashManager.Sha256( packet.Password );

            bool result = passwordManager.CheckPassword( password );

            if ( result )
            {
                result = passwordManager.DeletePassword( password );
                this.DeleteSession( packet.SessionKey );
            }

            ret.Value = result;
            return ret;
        }
Ejemplo n.º 3
0
        private object OnChangePassword( object message )
        {
            var packet = ( ChangePasswordMessage )message;
            var ret = new OperationResult();

            if ( !this.CheckSession( packet.SessionKey ) )
            {
                ret.Value = false;
                return ret;
            }

            if ( !this.IsPasswordCorrect( packet.OldPassword ) )
            {
                ret.Value = false;
                return ret;
            }

            if ( !this.IsPasswordCorrect( packet.NewPassword ) )
            {
                ret.Value = false;
                return ret;
            }

            PasswordManager passwordManager = new PasswordManager();

            string oldPassword = HashManager.Sha256( packet.OldPassword );

            bool result = passwordManager.CheckPassword( oldPassword );

            if ( result )
            {
                string newPassword = HashManager.Sha256( packet.NewPassword );
                result = passwordManager.ChangePassword( oldPassword, newPassword );
            }

            ret.Value = result;
            return ret;
        }
Ejemplo n.º 4
0
        private object OnCreateAuthSessionKey( object message )
        {
            var packet = ( CreateAuthSessionKeyMessage )message;
            var ret = new CreateAuthSessionKeyResult();

            PasswordManager passwordManager = new PasswordManager();

            string password = HashManager.Sha256( packet.Password );

            bool result = passwordManager.CheckPassword( password );

            ret.SessionKey = Guid.NewGuid().ToString();
            this.sessions.Add( ret.SessionKey );

            ret.Value = result;
            return ret;
        }
Ejemplo n.º 5
0
        private object OnAddPassword( object message )
        {
            var packet = ( AddPasswordMessage )message;
            var ret = new OperationResult();

            PasswordManager passwordManager = new PasswordManager();

            bool hasPasswords = passwordManager.HasPasswords();

            if ( !this.CheckSession( packet.SessionKey ) && hasPasswords )
            {
                ret.Value = false;
                return ret;
            }

            if ( !this.IsPasswordCorrect( packet.NewPassword ) )
            {
                ret.Value = false;
                return ret;
            }

            string newPassword = HashManager.Sha256( packet.NewPassword );

            passwordManager.InsertPassword( newPassword );

            ret.Value = true;
            return ret;
        }