I want to create a function that gives a trial period of one month upon initial registration on my website.
I would like to manipulate the function using the date object for that purpose, does anyone has a reciepe for this... Even just the program design would be appriciated.
When user logs in for first time, then store the first login time in SQL, and for consecutive logins check it against first login time, get the difference, if it is permissible authenticate him, or else tell him that his trial period is done...
I found this useful this writes the dates in a binary format which file can be place on the person machine. maybe in the hidden common app directory.
static string appDataFile;
static void Main(string[] args)
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
appDataPath = System.IO.Path.Combine(appDataPath, "MyApplication");
if (!System.IO.Directory.Exists(appDataPath))
System.IO.Directory.CreateDirectory(appDataPath);
appDataFile = System.IO.Path.Combine(appDataPath, "History.dat");
DateTime[] dates;
if (System.IO.File.Exists(appDataFile))
dates = ReadDates();
else
dates = new DateTime[] {DateTime.Now, DateTime.Now};
Console.WriteLine("First: {0}\r\nLast: {1}", dates[0], dates[1]);
dates[1] = DateTime.Now;
WriteDates(dates);
}
static DateTime[] ReadDates()
{
System.IO.FileStream appData = new System.IO.FileStream(
appDataFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
List<DateTime> result = new List<DateTime>();
using (System.IO.BinaryReader br = new System.IO.BinaryReader(appData))
{
while (br.PeekChar() > 0)
{
result.Add(new DateTime(br.ReadInt64()));
}
br.Close();
}
return result.ToArray();
}
static void WriteDates(IEnumerable<DateTime> dates)
{
System.IO.FileStream appData = new System.IO.FileStream(
appDataFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
List<DateTime> result = new List<DateTime>();
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(appData))
{
foreach(DateTime date in dates)
bw.Write(date.Ticks);
bw.Close();
}
}
With this code, all a user has to do is delete the file and their trial period would be reset. If you're gonna go about doing something as simple as this, why not just store thte values in the registry?
willnsub
Member
134 Points
62 Posts
Function that gives a trial period
Feb 24, 2012 10:48 AM|LINK
I want to create a function that gives a trial period of one month upon initial registration on my website.
I would like to manipulate the function using the date object for that purpose, does anyone has a reciepe for this... Even just the program design would be appriciated.
FACEBOOK: FACEBOOK.COM/MYGIGABOX
postonoh
Member
498 Points
259 Posts
Re: Function that gives a trial period
Feb 24, 2012 05:51 PM|LINK
I found this useful this writes the dates in a binary format which file can be place on the person machine. maybe in the hidden common app directory.
static string appDataFile; static void Main(string[] args) { string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); appDataPath = System.IO.Path.Combine(appDataPath, "MyApplication"); if (!System.IO.Directory.Exists(appDataPath)) System.IO.Directory.CreateDirectory(appDataPath); appDataFile = System.IO.Path.Combine(appDataPath, "History.dat"); DateTime[] dates; if (System.IO.File.Exists(appDataFile)) dates = ReadDates(); else dates = new DateTime[] {DateTime.Now, DateTime.Now}; Console.WriteLine("First: {0}\r\nLast: {1}", dates[0], dates[1]); dates[1] = DateTime.Now; WriteDates(dates); } static DateTime[] ReadDates() { System.IO.FileStream appData = new System.IO.FileStream( appDataFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); List<DateTime> result = new List<DateTime>(); using (System.IO.BinaryReader br = new System.IO.BinaryReader(appData)) { while (br.PeekChar() > 0) { result.Add(new DateTime(br.ReadInt64())); } br.Close(); } return result.ToArray(); } static void WriteDates(IEnumerable<DateTime> dates) { System.IO.FileStream appData = new System.IO.FileStream( appDataFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); List<DateTime> result = new List<DateTime>(); using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(appData)) { foreach(DateTime date in dates) bw.Write(date.Ticks); bw.Close(); } }ramiramilu
All-Star
95503 Points
14106 Posts
Re: Function that gives a trial period
Feb 24, 2012 05:58 PM|LINK
When user logs in for first time, then store the first login time in SQL, and for consecutive logins check it against first login time, get the difference, if it is permissible authenticate him, or else tell him that his trial period is done...
thnaks,
JumpStart
postonoh
Member
498 Points
259 Posts
Re: Function that gives a trial period
Feb 24, 2012 07:11 PM|LINK
This sound easier.! I like ramiramilu
rossisdead2
Participant
1313 Points
300 Posts
Re: Function that gives a trial period
Feb 24, 2012 08:55 PM|LINK
With this code, all a user has to do is delete the file and their trial period would be reset. If you're gonna go about doing something as simple as this, why not just store thte values in the registry?
postonoh
Member
498 Points
259 Posts
Re: Function that gives a trial period
Feb 24, 2012 09:30 PM|LINK
Yes this is true, Yet could have the app check file every time it loads the program. If file is missing close program.
willnsub
Member
134 Points
62 Posts
Re: Function that gives a trial period
Feb 25, 2012 06:51 AM|LINK
Thanks, this is what i wanted...
FACEBOOK: FACEBOOK.COM/MYGIGABOX