Git Repository Public Repository

CPE_learningsite

URLs

Copy to Clipboard

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CPE.App.Web.Models;
using System.Security.Cryptography;
using System.Configuration;
using System.Text;
using CPE.App.Web.Code;

namespace CPE.App.Web.Helpers
{
    public class VerifyAccess
    {
        public static bool IsValid(PurchasedCourse course)
        {
            return (((course.PurchaseDate).AddYears(1)) > DateTime.UtcNow);
        }
        public static bool VerifyTicket(string ticket, string contenturl, string firstname, string lastname, string email)
        {
            string secret = ConfigurationManager.AppSettings["CPE.SecretWord"];
            string seed = (contenturl + firstname + lastname + email + secret).ToLower();
            return ticket.Equals(sha256_hash(seed).Substring(4, 6));
        }
        public static bool VerifyTicket(string ticket, string contenturl, string firstname, string lastname, string email, string purchasedate)
        {
            string secret = ConfigurationManager.AppSettings["CPE.SecretWord"];
            string seed = (contenturl + firstname + lastname + email + purchasedate + secret).ToLower();
            return ticket.Equals(sha256_hash(seed).Substring(4, 6));
        }
        public static bool AccessBlocked(PurchasedCourse course)
        {
            BlockedPurchase blockedCourse = BaseController.Database.BlockedPurchases.SingleOrDefault(bc => bc.Ticket == course.Ticket && bc.ContentUrl == course.ContentUrl && bc.Email == course.Email);
            return (blockedCourse != null);
        }
        public static string generateTicket(string contenturl, string firstname, string lastname, string email, string purchasedate)
        {
            string secret = ConfigurationManager.AppSettings["CPE.SecretWord"];
            string seed = (contenturl + firstname + lastname + email + purchasedate + secret).ToLower();
            return sha256_hash(seed).Substring(4, 6);
        }
        private static String sha256_hash(String value)
        {
            using (SHA256 hash = SHA256Managed.Create())
            {
                return String.Join("", hash
                  .ComputeHash(Encoding.UTF8.GetBytes(value))
                  .Select(item => item.ToString("x2")));
            }
        }
    }
}

Commits for CPE_learningsiteCPE/CPE.App/CPE.App.Web/Helpers/VerifyAccess.cs

Diff revisions: vs.
Revision Author Commited Message
4cd176 ... v.shishlov Fri 27 Aug, 2021 14:33:17 +0000

initial commit