Files
Server-Dashboard/Server Dashboard/Security/SecureStringHelpers.cs
Rene Schwarz 4828f95ebb Issue #5
2021-08-06 12:35:46 +02:00

30 lines
970 B
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
namespace Server_Dashboard {
/// <summary>
/// Secure string helper class to unsecure the Password b4 it goes to the database
/// </summary>
public static class SecureStringHelpers {
//Unsecures a given password
public static string Unsecure(this SecureString secureString) {
//If empty return nothing
if (secureString == null)
return string.Empty;
//New zero pointer
var unmanagedString = IntPtr.Zero;
//Try to unsecure the string
try {
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureString);
return Marshal.PtrToStringUni(unmanagedString);
} finally {
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
}
}
}
}