diff --git a/src/Umbraco.Abstractions/Persistence/Repositories/IUserRepository.cs b/src/Umbraco.Abstractions/Persistence/Repositories/IUserRepository.cs
index 29ae581459..0d1a8764ae 100644
--- a/src/Umbraco.Abstractions/Persistence/Repositories/IUserRepository.cs
+++ b/src/Umbraco.Abstractions/Persistence/Repositories/IUserRepository.cs
@@ -20,8 +20,24 @@ namespace Umbraco.Core.Persistence.Repositories
///
///
///
+ [Obsolete("This method will be removed in future versions. Please use ExistsByUserName instead.")]
bool Exists(string username);
+ ///
+ /// Checks if a user with the username exists
+ ///
+ ///
+ ///
+ bool ExistsByUserName(string username);
+
+
+ ///
+ /// Checks if a user with the login exists
+ ///
+ ///
+ ///
+ bool ExistsByLogin(string login);
+
///
/// Gets a list of objects associated with a given group
///
diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs
index f3db5c5906..f35e820042 100644
--- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs
+++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs
@@ -626,6 +626,11 @@ ORDER BY colName";
}
public bool Exists(string username)
+ {
+ return ExistsByUserName(username);
+ }
+
+ public bool ExistsByUserName(string username)
{
var sql = SqlContext.Sql()
.SelectCount()
@@ -635,6 +640,16 @@ ORDER BY colName";
return Database.ExecuteScalar(sql) > 0;
}
+ public bool ExistsByLogin(string login)
+ {
+ var sql = SqlContext.Sql()
+ .SelectCount()
+ .From()
+ .Where(x => x.Login == login);
+
+ return Database.ExecuteScalar(sql) > 0;
+ }
+
///
/// Gets a list of objects associated with a given group
///
diff --git a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs
index f09e917e94..4dbc87dd4f 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs
@@ -109,9 +109,9 @@ namespace Umbraco.Core.Services.Implement
User user;
using (var scope = ScopeProvider.CreateScope())
{
- var loginExists = scope.Database.ExecuteScalar("SELECT COUNT(id) FROM umbracoUser WHERE userLogin = @Login", new { Login = username }) != 0;
+ var loginExists = _userRepository.ExistsByLogin(username);
if (loginExists)
- throw new ArgumentException("Login already exists"); // causes rollback // causes rollback
+ throw new ArgumentException("Login already exists"); // causes rollback
user = new User(_globalSettings)
{