summaryrefslogtreecommitdiff
path: root/VPNAuth.Server/PkceUtils.cs
blob: a11926ea7c04197ffdc5052379f82e63db815dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace VPNAuth.Server;

public static class PkceUtils
{
    private static string _codeChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";

    public static string GenerateCode(int length = 10)
    {
        string code = "";
        for (int i = 0; i < length; i++)
            code += _codeChars[new Random().Next(_codeChars.Length)]; // TODO: Is that function random enough?
        return code;
    }

    public static string GenerateToken(int length = 20)
        => GenerateCode(length); // TODO: maybe add more possible chars then for GenerateCode
}