Skip to content

Instantly share code, notes, and snippets.

View foontzoot's full-sized avatar
🏠
Working from home

foontzoot foontzoot

🏠
Working from home
View GitHub Profile
@foontzoot
foontzoot / EncodePassword.cs
Created September 23, 2016 02:10
A working example of password encoding for ASP.NET
public string EncodePassword(string pass, string salt)
{
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] src = Convert.FromBase64String(salt);
byte[] dst = new byte[src.Length + bytes.Length];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
byte[] inArray = algorithm.ComputeHash(dst);
return Convert.ToBase64String(inArray);
@foontzoot
foontzoot / AntiXsrf.Master.cs
Last active October 18, 2016 02:07
Helps to protect against XSRF attacks
public partial class HuntGroup : System.Web.UI.MasterPage
{
private const string AntiXsrfTokenKey = "__AntiXsrfToken";
private const string AntiXsrfUserNameKey = "__AntiXsrfUserName";
private string _antiXsrfTokenValue;
protected void Page_Init(object sender, EventArgs e)
{
// The code below helps to protect against XSRF attacks
var requestCookie = Request.Cookies[AntiXsrfTokenKey];
DECLARE @TableName VARCHAR(MAX);
DECLARE @TableSchema VARCHAR(MAX);
DECLARE @result varchar(max);
SET @TableName = 'Contact'; -- your table name
SET @TableSchema = 'dbo'; -- your schema name
SET @result = '';
SET @result = @result + 'using System;' + CHAR(13) + CHAR(13);
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE function A2ROMAN(@n int )
--Converts an arabic numeral to roman, as a string.
returns VARCHAR(20)
as
SELECT r.[RegistrationId], dc.[DigitalCodeId]
FROM
(
SELECT [RegistrationId], row_number() OVER (ORDER BY [RegistrationId]) AS row_num
FROM [dbo].[Registration]
WHERE [JobNumber] = 12897 AND [OrderNumber] = 5405
) r
JOIN
(
SELECT [DigitalCodeId], row_number() OVER (ORDER BY [DigitalCodeId]) as row_num
-- SQL Server string to date / datetime conversion - datetime string format sql server
-- MSSQL string to datetime conversion - convert char to date - convert varchar to date
-- Subtract 100 from style number (format) for yy instead yyyy (or ccyy with century)
SELECT convert(datetime, 'Oct 23 2012 11:01AM', 100) -- mon dd yyyy hh:mmAM (or PM)
SELECT convert(datetime, 'Oct 23 2012 11:01AM') -- 2012-10-23 11:01:00.000
-- Without century (yy) string date conversion - convert string to datetime function
SELECT convert(datetime, 'Oct 23 12 11:01AM', 0) -- mon dd yy hh:mmAM (or PM)
SELECT convert(datetime, 'Oct 23 12 11:01AM') -- 2012-10-23 11:01:00.000
-- =================================================================
-- Create Stored Procedure Template for Windows Azure SQL Database
-- =================================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =======================================================
-- Author: Sinisa Petkovic
-- Create date: Nov 11, 2015
SELECT FirstName
, LastName
, Email
, Address1
, Address2
, City
, State
, PostalCode
, Country
, HomePhone
INSERT INTO [TableName]
SELECT *
FROM OPENDATASOURCE
(
'SQLOLEDB','Data Source=XXX.XXX.XXX.XXX;User ID=USERNAME;Password=PASSWORD;'
).DATABASE_NAME.dbo.[TableName]
WHERE CouponId = @coupon_id;
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'DBMailAccount',
@email_address = 'test@test.com',
@replyto_address = 'noreply@test.com',
@display_name = 'SQL Server Agent Automated Mailer',
@mailserver_name = 'smtp.test.com',
@port = 587,
@username = 'user@test.com',
@password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';