Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Martyr2 Martyr2

🎯
Focusing
Block or report user

Report or block Martyr2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Martyr2
Martyr2 / ValidIP.cs
Created Jun 1, 2017
A few utility functions for checking if an IP address is a IPv4 or IPv6 address.
View ValidIP.cs
/// <summary>
/// Checks if the supplied address string is an IPv4 version IP address.
/// </summary>
/// <param name="address">IP address to check for being IPv4 (minus any port)</param>
/// <returns>True if the address conforms to IPv4. False otherwise.</returns>
public static bool IsIPv4(string address)
{
string octetRegex = "([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])";
System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(String.Format(@"^{0}\.{0}\.{0}\.{0}$", octetRegex));
@Martyr2
Martyr2 / EncryptDecrypt.cs
Created Jun 1, 2017
Simple encryption and decryption functions that make the process easy to use.
View EncryptDecrypt.cs
/// <summary>
/// Decrypts a string that was encrypted using the encrypt method in this library.
/// </summary>
/// <param name="input">Encrypted string in base 64</param>
/// <param name="key">Salt key used in encryption</param>
/// <returns>Decrypted string data</returns>
public static string Decrypt(string input, string key)
{
byte[] inputArray = Convert.FromBase64String(input);
@Martyr2
Martyr2 / GetRandomString.cs
Created Jun 1, 2017
Generates a random string of a specified length. Defaults to 25 characters.
View GetRandomString.cs
/// <summary>
/// Gets a random crypto string
/// </summary>
/// <param name="length">The length of the string to generate</param>
/// <remarks>Typically the length is 25</remarks>
/// <returns>Returns a random string of characters of length size.</returns>
public static string GetRandomString(int length = 25)
{
// Set the character space
string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@Martyr2
Martyr2 / GetVisitorIPAddress.cs
Created Jun 1, 2017
Gets the visitors IP address for an ASP.NET address. Will take a proxy address if real visitor IP is not forwarded along by the proxy.
View GetVisitorIPAddress.cs
/// <summary>
/// Get the IP address of the current client visiting the website.
/// </summary>
/// <returns>String representing the IP address</returns>
public static string GetVisitorIPAddress()
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipAddress)) {
@Martyr2
Martyr2 / Webhook.cs
Created Nov 27, 2016
A C# .NET Web API class for handling webhooks from Chargify. Supply the class with request headers and the request body from a incoming webhook event to have it work its magic.
View Webhook.cs
/// <summary>
/// Represents a webhook from Chargify.
/// </summary>
public class Webhook
{
private Dictionary<string, string> headerPayload = new Dictionary<string,string>();
private Dictionary<string, string> bodyPayload = new Dictionary<string, string>();
private string signatureHmacKey = string.Empty;
private string sharedSiteKey = <Chargify Store Site Key Here>;
You can’t perform that action at this time.