-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration.cs
More file actions
76 lines (67 loc) · 2.25 KB
/
registration.cs
File metadata and controls
76 lines (67 loc) · 2.25 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Text.RegularExpressions;
public class registration : MonoBehaviour
{
[Header("Register")]
public TMP_InputField nameField;
public TMP_InputField passwordField;
[SerializeField] private TMP_Text registerMessage;
[SerializeField] private Button submitButton;
private void Start()
{
registerMessage.text = "";
nameField.onValueChanged.AddListener(delegate { VerifyInputs(); });
passwordField.onValueChanged.AddListener(delegate { VerifyInputs(); });
}
public async void OnRegisterPressed()
{
// called by the register button
VerifyInputs();
try
{
(bool result, int errorCode, string message) = await SQLManager.RegisterUser(nameField.text, passwordField.text);
if (result)
{
registerMessage.text = "Successfully registered!";
}
else
{
switch (errorCode)
{
case 3:
// Username already exists
registerMessage.text = "Username already exists. Please choose another username.";
break;
case 22:
// Database insertion error
registerMessage.text = "Could not create account. Please try again later.";
break;
default:
// Generic error
registerMessage.text = $"Registration failed: {message}";
break;
}
}
}
catch
{
registerMessage.text = "An unexpected error occured, please try again";
}
}
public void VerifyInputs()
{
submitButton.interactable = nameField.text.Length > 3 && VerifyPassword(passwordField.text);
}
private bool VerifyPassword(string password)
{
if (string.IsNullOrEmpty(password))
{
return false;
}
// Regex pattern to check password criteria
string pattern = @"^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[^A-Za-z\d]).{8,}$";
return Regex.IsMatch(password, pattern);
}
}