Skip to content

Instantly share code, notes, and snippets.

@AydinAdn
AydinAdn / RandomStringGenerator.cs
Created March 24, 2023 13:31
RandomStringGenerator
public static class RandomStringGenerator
{
private static readonly char[] defaultCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToArray();
public static string GenerateString(int length)
{
string text = "";
for (int i = 0; i < length; i++)
{
RandomNumberGenerator rNGCryptoServiceProvider = RandomNumberGenerator.Create();
using System.Linq;
using System.Security.Cryptography;
namespace Cryptography
{
public interface IRSGCryptoService
{
/// <summary>
/// Generates a cryptographically secure string of specified length
/// </summary>

Prerequisites

Root access to an Ubuntu 16.04 installation via SSH, first run these commands before anything else.

sudo apt-get update 
sudo apt-get install openvpn easy-rsa 

1. Install OpenVPN Server

// https://stackoverflow.com/questions/55498470/mocking-streamreader-in-c-sharp-for-unit-test/
public static void Main()
{
Mock<IFileManager> mockFileManager = new Mock<IFileManager>();
string fakeFileContents = "Hello world";
byte[] fakeFileBytes = Encoding.UTF8.GetBytes(fakeFileContents);
MemoryStream fakeMemoryStream = new MemoryStream(fakeFileBytes);
mockFileManager.Setup(fileManager => fileManager.StreamReader(It.IsAny<string>()))
function getTestPersonaLoginCredentials(cb) {
http.get({
host: 'personatestuser.org',
path: '/email'
}, function(res) {
// explicitly treat incoming data as utf8 (avoids issues with multi-byte chars)
res.setEncoding('utf8');
// incrementally capture the incoming response body
ko.bindingHandlers.datalist = (function () {
function getVal(rawItem, prop) {
var item = ko.unwrap(rawItem);
return item && prop ? ko.unwrap(item[prop]) : item;
}
function findItem(options, prop, ref) {
return ko.utils.arrayFirst(options, function (item) {
return ref === getVal(item, prop);
});