﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RedditSavedPostOrganizer.Services
{
    //A "State", as Reddit calls it, is a random string sent from our app in a query string to
    //the Reddit login page.  After the user is directed back to our app, Reddit sends that string
    //back in the Query string, to be verified by our app to make sure that " only authorization 
    //requests you've started are ones you finish.  This class generates that random, 15 character string.

    public class StateGenerator
    {
        public string Generate()
        {
            
            string numbers = "0123456789";
            string LargeAplhabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string SmallAplhabets = "abcdefghijklmnopqrstuvwxyz";
            string allowedChars = numbers + LargeAplhabets + SmallAplhabets;
            Random objrandom = new Random();
            char[] chars = new char[15];

            for (int i = 0; i < 15; i++)
            {
                chars[i] = allowedChars[Convert.ToInt32((allowedChars.Length - 1) * objrandom.NextDouble())];
            }
            string otp = new string(chars);

            return otp;      
        }
    }
}
