Good day
I developed a WP8 app that requires the user to use an activation PIN before accessing the app. whenever the user input the right PIN they will have access to the app and it works fine
But the issue am facing is whenever the user closes the app and wants to reuse the app it asks for the PIN, i want the user to activate the app once with a correct PIN. The app not having to asks for the PIN when next they want to use the app unless they uninstall the app
How can i achieve this in c# ?
Regards and reply soon
Wim SturkenboomPosted Oct 6, 2014, 1:38 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Configuration;
namespace StorePin
{
class Program
{
static void Main(string[] args)
{
if (!File.Exists("pinfile.txt"))
{
Console.Write("Please enter your pin: ");
string pin1 = Console.ReadLine();
using (StreamWriter sw = new StreamWriter("pinfile.txt"))
{
sw.WriteLine(pin1);
}
}
else
{
Console.WriteLine("Pin file found");
}
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationElement kvce = config.AppSettings.Settings["pin"];
if (kvce == null)
{
Console.Write("Please enter your pin: ");
string pin2 = Console.ReadLine();
config.AppSettings.Settings.Add("pin", pin2);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
else
{
Console.WriteLine("Pin found in appSettings");
}
Console.ReadLine();
}
}
}
The second part is based on http://social.msdn.microsoft.com/Forums/vstudio/en-US/77b87843-ae0b-463d-b50e-b6b8e9175e50/write-to-appconfig-at-runtime-very-urgent?forum=csharpgeneral
Note 1: the app.config part might not work as you expect when running from within visual studio because VS copies the original app.Config to the output directory and overwrites the existing (new) configuration there. It will work when running from windows explorer.
Note 2: the program only checks if there is a pinfile or a key in app.Config; for the demo I have written the pin in there. It's not secure, it does not validate if the pin is correct and so on. If it needs to be secure, you need to add some intelligence to the pin and store in encrypted format, decrypt and check if it's a valid pin.
Wim SturkenboomPosted Oct 6, 2014, 4:28 AM
JOHN JOHNNNYPosted Oct 5, 2014, 5:00 PM
Thank you for the reply it really makes sense, can you recommend a tutorial or code snippet to implement both methods
I have attached my code to this reply
Regards and reply soon
Wim SturkenboomPosted Oct 5, 2014, 12:26 PM
Alternatively, you can store the pin under a key in App.config or in an entry in the registry. same principles apply (not existing, prompt and store; else read).