![]() ![]() Public static bool CheckSQLCredentialsIfLoginExists(string username, string password)īool SqlUserExists = SqlLoginExists(username) Ĭonnection.ConnectionString = "Data Source=. Using (SqlDataReader reader = command.ExecuteReader()) Using (SqlCommand command = new SqlCommand(sql_command, connection)) String sql_command = "SELECT count(*) FROM sys.server_principals WHERE name = N'" + username + "'" ![]() SqlConnection connection = new SqlConnection() Ĭonnection.ConnectionString = "Data Source=. My solution in C# is with the help of Roger as follows: private static bool SqlLoginExists(string username) The credential used to access the file is different whether you logged in with SQL login or a Windows login. if 'myusername' exists: SELECT * FROM sys.server_principals WHERE name = N'myusername'īut how can I check if 'myusername' and a password 'wrong_password' supplied by the user are correct? 2 Answers Sorted by: 8 It depends, and I'm afraid Martin give you only part of the answer. I can create an SQL login account for an user as follows: CREATE LOGIN WITH PASSWORD = N'mypassword', CHECK_POLICY= OFF ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |