Skip to Content

Scripting Example - Validate an Encrypted Password Field

This Plugin example was designed for a custom login form, where the requirement was to validate a login attempt against an encrypted password field. This script provides one to one validations for password login.

Standard Validations do not currently support validating against an encrypted fields, so a Plugin was used to accomplish the requirement.

Script Example

using System;
using System.Linq;
using System.Text;
using Vinyl.Sdk.Events;
using Vinyl.Sdk.Filtering;

var tableId = Guid.Parse("TableID the Plugin will validate against");
var currentAccountID = Row["ViewAccountID"].Value;
string currentPassword = Row["CurrentPass"].GetValueAsString();
var filterBuilder = Services.GetService<FilterBuilder>();
var filter = filterBuilder.From(tableId).Where("AccountID", ComparisonOperator.Equals, currentAccountID);

var eventService = Services.GetService<IEventService>();
EventTable eventTable = await eventService.InvokeFilterEventAsync(filter);

var user = eventTable.Rows.SingleOrDefault();
if (user == null) {
    Fail();

    return;
}


string password = user["PasswordEncrypted"].Value as string;
if (password == null) {
    var passwordBytes = user["PasswordEncrypted"].GetValueAsByteArray();
    password = Encoding.UTF8.GetString(passwordBytes);
}


if (string.Equals(currentPassword, password)) {
    return;
}

Fail();