From d5761dbcd1b64b29aebfc4ffbb04ab75c40dd16d Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 7 Dec 2016 18:02:52 +0100 Subject: [PATCH] Restrict number of characters in signup fields to prevent database errors ("string would be truncated") --- .../Our/Controllers/RegisterController.cs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/OurUmbraco/Our/Controllers/RegisterController.cs b/OurUmbraco/Our/Controllers/RegisterController.cs index 94f23d0f..382a0080 100644 --- a/OurUmbraco/Our/Controllers/RegisterController.cs +++ b/OurUmbraco/Our/Controllers/RegisterController.cs @@ -64,19 +64,18 @@ namespace OurUmbraco.Our.Controllers // these values are enforced in MemberDto which is internal ;-( // we should really have ways to query for Core meta-data! - const int maxEmailLength = 900; // 1000*.9 for safety - const int maxLoginNameLength = 900; // 1000*.9 for safety - const int maxPasswordLength = 900; // 1000*.9 for safety - const int maxPropertyLength = 900; // keep it safe too + const int maxEmailLength = 400; + const int maxLoginNameLength = 200; + const int maxPasswordLength = 400; + const int maxPropertyLength = 400; - if (model.Email.Length > maxEmailLength - || model.Name.Length > maxLoginNameLength - || model.Password.Length > maxPasswordLength - || model.Location.Length > maxPropertyLength - || model.Longitude.Length > maxPropertyLength - || model.Latitude.Length > maxPropertyLength - || model.Company.Length > maxPropertyLength - || model.TwitterAlias.Length > maxPropertyLength + if (model.Email != null && model.Email.Length > maxEmailLength + || model.Name != null && model.Name.Length > maxLoginNameLength + || model.Password != null && model.Password.Length > maxPasswordLength + || model.Location != null && model.Location.Length > maxPropertyLength + || model.Longitude != null && model.Longitude.Length > maxPropertyLength + || model.Latitude != null && model.Latitude.Length > maxPropertyLength + || model.TwitterAlias != null && model.TwitterAlias.Length > maxPropertyLength ) { // has to be a rogue registration