How to check if user is log in once enter a form using c# winform only, no asp.netc#
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
NO asp.net c# used
I need to know if user is login once he/she enter a form and if he/she is not login, he goes back to the login form. Everywhere I saw people use asp.net to achieve that but I want to know how to do it without using asp.net.
public DataTable Login(String Username, String Password)
{
server = "localhost";
database = "xxxx";
uid = "root";
password = "";
string MySQLConnectionString = $"datasource=127.0.0.1;port = 3306; SERVER={server}; DATABASE={database}; USERNAME={uid}; PASSWORD={password};sslmode=none";
MySqlConnection db_Conn = new MySqlConnection(MySQLConnectionString);
MySqlCommand cmd = new MySqlCommand();
db_Conn.ConnectionString = MySQLConnectionString;
string username_txtfield = username_txtbox.Text;
string pw_txtfield = password_txtbox.Text;
try
{
db_Conn.Open();
cmd.Connection = db_Conn;
cmd.CommandText = "SELECT count(*),user_id,person_username,role_id FROM user_tb " +
"WHERE person_username=@username " +
"AND user_password=@password";
cmd.Prepare();
cmd.Parameters.AddWithValue("@username", username_txtfield);
cmd.Parameters.AddWithValue("@password", pw_txtfield);
MySqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
db_Conn.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
login btn in my login form
private void button1_Click(object sender, EventArgs e)
{
//login();
try
{
DataTable result = Login(username_txtbox.Text, password_txtbox.Text);
if (result.Rows.Count == 1)
{
this.Hide();
string role = result.Rows[0]["role_id"].ToString();
switch (role)
{
case "3":
MessageBox.Show("User login successfully!");
user_form_page();
break;
case "1":
MessageBox.Show("Admin login successfully!");
//this.Hide();
Admin_page admin_form = new Admin_page();
admin_form.ShowDialog();
this.Close();
break;
}
}
else
{
MessageBox.Show("INVALID USERNAME OR PASSWORD");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
c# mysql winforms
|
show 1 more comment
NO asp.net c# used
I need to know if user is login once he/she enter a form and if he/she is not login, he goes back to the login form. Everywhere I saw people use asp.net to achieve that but I want to know how to do it without using asp.net.
public DataTable Login(String Username, String Password)
{
server = "localhost";
database = "xxxx";
uid = "root";
password = "";
string MySQLConnectionString = $"datasource=127.0.0.1;port = 3306; SERVER={server}; DATABASE={database}; USERNAME={uid}; PASSWORD={password};sslmode=none";
MySqlConnection db_Conn = new MySqlConnection(MySQLConnectionString);
MySqlCommand cmd = new MySqlCommand();
db_Conn.ConnectionString = MySQLConnectionString;
string username_txtfield = username_txtbox.Text;
string pw_txtfield = password_txtbox.Text;
try
{
db_Conn.Open();
cmd.Connection = db_Conn;
cmd.CommandText = "SELECT count(*),user_id,person_username,role_id FROM user_tb " +
"WHERE person_username=@username " +
"AND user_password=@password";
cmd.Prepare();
cmd.Parameters.AddWithValue("@username", username_txtfield);
cmd.Parameters.AddWithValue("@password", pw_txtfield);
MySqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
db_Conn.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
login btn in my login form
private void button1_Click(object sender, EventArgs e)
{
//login();
try
{
DataTable result = Login(username_txtbox.Text, password_txtbox.Text);
if (result.Rows.Count == 1)
{
this.Hide();
string role = result.Rows[0]["role_id"].ToString();
switch (role)
{
case "3":
MessageBox.Show("User login successfully!");
user_form_page();
break;
case "1":
MessageBox.Show("Admin login successfully!");
//this.Hide();
Admin_page admin_form = new Admin_page();
admin_form.ShowDialog();
this.Close();
break;
}
}
else
{
MessageBox.Show("INVALID USERNAME OR PASSWORD");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
c# mysql winforms
1
Fun fact: there is a WinForms tag you can attach to your post so that it gets the proper attention without all that noise in the title
– Nat Pongjardenlarp
Nov 23 '18 at 18:17
done thanks, but what about the question?
– Emanula Sohn
Nov 23 '18 at 18:20
For what I understand, you can create a class "User" that equals null when loading. But when the user is connected:User user = new User(required information)
. So when you need to know if the user is connected or not, you just check:if(user == null)
– Olivier Belanger
Nov 23 '18 at 18:24
u mean I should add a user which username/password = null or something like that in my database?
– Emanula Sohn
Nov 23 '18 at 18:25
@EmanulaSohn look at Emad answer, you create a class with a username and password, and if the user enter the correct credentials, he can login.
– Olivier Belanger
Nov 23 '18 at 18:30
|
show 1 more comment
NO asp.net c# used
I need to know if user is login once he/she enter a form and if he/she is not login, he goes back to the login form. Everywhere I saw people use asp.net to achieve that but I want to know how to do it without using asp.net.
public DataTable Login(String Username, String Password)
{
server = "localhost";
database = "xxxx";
uid = "root";
password = "";
string MySQLConnectionString = $"datasource=127.0.0.1;port = 3306; SERVER={server}; DATABASE={database}; USERNAME={uid}; PASSWORD={password};sslmode=none";
MySqlConnection db_Conn = new MySqlConnection(MySQLConnectionString);
MySqlCommand cmd = new MySqlCommand();
db_Conn.ConnectionString = MySQLConnectionString;
string username_txtfield = username_txtbox.Text;
string pw_txtfield = password_txtbox.Text;
try
{
db_Conn.Open();
cmd.Connection = db_Conn;
cmd.CommandText = "SELECT count(*),user_id,person_username,role_id FROM user_tb " +
"WHERE person_username=@username " +
"AND user_password=@password";
cmd.Prepare();
cmd.Parameters.AddWithValue("@username", username_txtfield);
cmd.Parameters.AddWithValue("@password", pw_txtfield);
MySqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
db_Conn.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
login btn in my login form
private void button1_Click(object sender, EventArgs e)
{
//login();
try
{
DataTable result = Login(username_txtbox.Text, password_txtbox.Text);
if (result.Rows.Count == 1)
{
this.Hide();
string role = result.Rows[0]["role_id"].ToString();
switch (role)
{
case "3":
MessageBox.Show("User login successfully!");
user_form_page();
break;
case "1":
MessageBox.Show("Admin login successfully!");
//this.Hide();
Admin_page admin_form = new Admin_page();
admin_form.ShowDialog();
this.Close();
break;
}
}
else
{
MessageBox.Show("INVALID USERNAME OR PASSWORD");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
c# mysql winforms
NO asp.net c# used
I need to know if user is login once he/she enter a form and if he/she is not login, he goes back to the login form. Everywhere I saw people use asp.net to achieve that but I want to know how to do it without using asp.net.
public DataTable Login(String Username, String Password)
{
server = "localhost";
database = "xxxx";
uid = "root";
password = "";
string MySQLConnectionString = $"datasource=127.0.0.1;port = 3306; SERVER={server}; DATABASE={database}; USERNAME={uid}; PASSWORD={password};sslmode=none";
MySqlConnection db_Conn = new MySqlConnection(MySQLConnectionString);
MySqlCommand cmd = new MySqlCommand();
db_Conn.ConnectionString = MySQLConnectionString;
string username_txtfield = username_txtbox.Text;
string pw_txtfield = password_txtbox.Text;
try
{
db_Conn.Open();
cmd.Connection = db_Conn;
cmd.CommandText = "SELECT count(*),user_id,person_username,role_id FROM user_tb " +
"WHERE person_username=@username " +
"AND user_password=@password";
cmd.Prepare();
cmd.Parameters.AddWithValue("@username", username_txtfield);
cmd.Parameters.AddWithValue("@password", pw_txtfield);
MySqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
db_Conn.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
login btn in my login form
private void button1_Click(object sender, EventArgs e)
{
//login();
try
{
DataTable result = Login(username_txtbox.Text, password_txtbox.Text);
if (result.Rows.Count == 1)
{
this.Hide();
string role = result.Rows[0]["role_id"].ToString();
switch (role)
{
case "3":
MessageBox.Show("User login successfully!");
user_form_page();
break;
case "1":
MessageBox.Show("Admin login successfully!");
//this.Hide();
Admin_page admin_form = new Admin_page();
admin_form.ShowDialog();
this.Close();
break;
}
}
else
{
MessageBox.Show("INVALID USERNAME OR PASSWORD");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
c# mysql winforms
c# mysql winforms
edited Nov 23 '18 at 19:33
Emanula Sohn
asked Nov 23 '18 at 18:13
Emanula SohnEmanula Sohn
235
235
1
Fun fact: there is a WinForms tag you can attach to your post so that it gets the proper attention without all that noise in the title
– Nat Pongjardenlarp
Nov 23 '18 at 18:17
done thanks, but what about the question?
– Emanula Sohn
Nov 23 '18 at 18:20
For what I understand, you can create a class "User" that equals null when loading. But when the user is connected:User user = new User(required information)
. So when you need to know if the user is connected or not, you just check:if(user == null)
– Olivier Belanger
Nov 23 '18 at 18:24
u mean I should add a user which username/password = null or something like that in my database?
– Emanula Sohn
Nov 23 '18 at 18:25
@EmanulaSohn look at Emad answer, you create a class with a username and password, and if the user enter the correct credentials, he can login.
– Olivier Belanger
Nov 23 '18 at 18:30
|
show 1 more comment
1
Fun fact: there is a WinForms tag you can attach to your post so that it gets the proper attention without all that noise in the title
– Nat Pongjardenlarp
Nov 23 '18 at 18:17
done thanks, but what about the question?
– Emanula Sohn
Nov 23 '18 at 18:20
For what I understand, you can create a class "User" that equals null when loading. But when the user is connected:User user = new User(required information)
. So when you need to know if the user is connected or not, you just check:if(user == null)
– Olivier Belanger
Nov 23 '18 at 18:24
u mean I should add a user which username/password = null or something like that in my database?
– Emanula Sohn
Nov 23 '18 at 18:25
@EmanulaSohn look at Emad answer, you create a class with a username and password, and if the user enter the correct credentials, he can login.
– Olivier Belanger
Nov 23 '18 at 18:30
1
1
Fun fact: there is a WinForms tag you can attach to your post so that it gets the proper attention without all that noise in the title
– Nat Pongjardenlarp
Nov 23 '18 at 18:17
Fun fact: there is a WinForms tag you can attach to your post so that it gets the proper attention without all that noise in the title
– Nat Pongjardenlarp
Nov 23 '18 at 18:17
done thanks, but what about the question?
– Emanula Sohn
Nov 23 '18 at 18:20
done thanks, but what about the question?
– Emanula Sohn
Nov 23 '18 at 18:20
For what I understand, you can create a class "User" that equals null when loading. But when the user is connected:
User user = new User(required information)
. So when you need to know if the user is connected or not, you just check: if(user == null)
– Olivier Belanger
Nov 23 '18 at 18:24
For what I understand, you can create a class "User" that equals null when loading. But when the user is connected:
User user = new User(required information)
. So when you need to know if the user is connected or not, you just check: if(user == null)
– Olivier Belanger
Nov 23 '18 at 18:24
u mean I should add a user which username/password = null or something like that in my database?
– Emanula Sohn
Nov 23 '18 at 18:25
u mean I should add a user which username/password = null or something like that in my database?
– Emanula Sohn
Nov 23 '18 at 18:25
@EmanulaSohn look at Emad answer, you create a class with a username and password, and if the user enter the correct credentials, he can login.
– Olivier Belanger
Nov 23 '18 at 18:30
@EmanulaSohn look at Emad answer, you create a class with a username and password, and if the user enter the correct credentials, he can login.
– Olivier Belanger
Nov 23 '18 at 18:30
|
show 1 more comment
1 Answer
1
active
oldest
votes
Of course the ASP.Net identity services is a mature way of doing such a task but if you want you can have your own method of authentication but, you will need to implement many things.
Many of the stuff you need is actually based on the scenario you are implementing but the most basic thing you need is a static user that will be used via your methods to see if the user is already logged in or not. For example you can have:
public static class Authentication
{
public static User CurrentUser { get; private set; }
public static bool Login(User user)
{
if(user == null)
throw new ArgumentException("Invalid user","user");
CurrentUser = user;
}
}
This is just the most basic implementation of such a thing you can then check if CurrentUser
is null or not and direct user to login page or show her the results.
As your requirements grow you will need to implement more stuff. A logout, a local or remote database for users, store currently logged in user in disk so that she doesn't need to login again after closing the app and many other things
Edit
Based on your new information you can add this line to your login button click like this:
if (result.Rows.Count == 1)
{
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
//The rest of code
}
I have also presumed that you have a class like:
class User
{
public string Name { get; }
public int RoleId { get; }
public User(string name, int roleId)
{
Name = name;
RoleId = roleId;
}
}
And then you have to check Authentication.CurrentUser
against null
in your user form or admin form constructors to ensure user is login you can use the information in Authentication.CurrentUser
to show logged in user name or role or any other info.
I hope this helps you. If you need more info please say so.
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error onUser, Match and currentUser
...
– Emanula Sohn
Nov 23 '18 at 19:35
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
Getting error onAuthentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string ANDpublic static bool *Login*(User user)
-> not all code path return a value
– Emanula Sohn
Nov 23 '18 at 21:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451318%2fhow-to-check-if-user-is-log-in-once-enter-a-form-using-c-sharp-winform-only-no%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Of course the ASP.Net identity services is a mature way of doing such a task but if you want you can have your own method of authentication but, you will need to implement many things.
Many of the stuff you need is actually based on the scenario you are implementing but the most basic thing you need is a static user that will be used via your methods to see if the user is already logged in or not. For example you can have:
public static class Authentication
{
public static User CurrentUser { get; private set; }
public static bool Login(User user)
{
if(user == null)
throw new ArgumentException("Invalid user","user");
CurrentUser = user;
}
}
This is just the most basic implementation of such a thing you can then check if CurrentUser
is null or not and direct user to login page or show her the results.
As your requirements grow you will need to implement more stuff. A logout, a local or remote database for users, store currently logged in user in disk so that she doesn't need to login again after closing the app and many other things
Edit
Based on your new information you can add this line to your login button click like this:
if (result.Rows.Count == 1)
{
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
//The rest of code
}
I have also presumed that you have a class like:
class User
{
public string Name { get; }
public int RoleId { get; }
public User(string name, int roleId)
{
Name = name;
RoleId = roleId;
}
}
And then you have to check Authentication.CurrentUser
against null
in your user form or admin form constructors to ensure user is login you can use the information in Authentication.CurrentUser
to show logged in user name or role or any other info.
I hope this helps you. If you need more info please say so.
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error onUser, Match and currentUser
...
– Emanula Sohn
Nov 23 '18 at 19:35
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
Getting error onAuthentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string ANDpublic static bool *Login*(User user)
-> not all code path return a value
– Emanula Sohn
Nov 23 '18 at 21:38
add a comment |
Of course the ASP.Net identity services is a mature way of doing such a task but if you want you can have your own method of authentication but, you will need to implement many things.
Many of the stuff you need is actually based on the scenario you are implementing but the most basic thing you need is a static user that will be used via your methods to see if the user is already logged in or not. For example you can have:
public static class Authentication
{
public static User CurrentUser { get; private set; }
public static bool Login(User user)
{
if(user == null)
throw new ArgumentException("Invalid user","user");
CurrentUser = user;
}
}
This is just the most basic implementation of such a thing you can then check if CurrentUser
is null or not and direct user to login page or show her the results.
As your requirements grow you will need to implement more stuff. A logout, a local or remote database for users, store currently logged in user in disk so that she doesn't need to login again after closing the app and many other things
Edit
Based on your new information you can add this line to your login button click like this:
if (result.Rows.Count == 1)
{
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
//The rest of code
}
I have also presumed that you have a class like:
class User
{
public string Name { get; }
public int RoleId { get; }
public User(string name, int roleId)
{
Name = name;
RoleId = roleId;
}
}
And then you have to check Authentication.CurrentUser
against null
in your user form or admin form constructors to ensure user is login you can use the information in Authentication.CurrentUser
to show logged in user name or role or any other info.
I hope this helps you. If you need more info please say so.
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error onUser, Match and currentUser
...
– Emanula Sohn
Nov 23 '18 at 19:35
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
Getting error onAuthentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string ANDpublic static bool *Login*(User user)
-> not all code path return a value
– Emanula Sohn
Nov 23 '18 at 21:38
add a comment |
Of course the ASP.Net identity services is a mature way of doing such a task but if you want you can have your own method of authentication but, you will need to implement many things.
Many of the stuff you need is actually based on the scenario you are implementing but the most basic thing you need is a static user that will be used via your methods to see if the user is already logged in or not. For example you can have:
public static class Authentication
{
public static User CurrentUser { get; private set; }
public static bool Login(User user)
{
if(user == null)
throw new ArgumentException("Invalid user","user");
CurrentUser = user;
}
}
This is just the most basic implementation of such a thing you can then check if CurrentUser
is null or not and direct user to login page or show her the results.
As your requirements grow you will need to implement more stuff. A logout, a local or remote database for users, store currently logged in user in disk so that she doesn't need to login again after closing the app and many other things
Edit
Based on your new information you can add this line to your login button click like this:
if (result.Rows.Count == 1)
{
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
//The rest of code
}
I have also presumed that you have a class like:
class User
{
public string Name { get; }
public int RoleId { get; }
public User(string name, int roleId)
{
Name = name;
RoleId = roleId;
}
}
And then you have to check Authentication.CurrentUser
against null
in your user form or admin form constructors to ensure user is login you can use the information in Authentication.CurrentUser
to show logged in user name or role or any other info.
I hope this helps you. If you need more info please say so.
Of course the ASP.Net identity services is a mature way of doing such a task but if you want you can have your own method of authentication but, you will need to implement many things.
Many of the stuff you need is actually based on the scenario you are implementing but the most basic thing you need is a static user that will be used via your methods to see if the user is already logged in or not. For example you can have:
public static class Authentication
{
public static User CurrentUser { get; private set; }
public static bool Login(User user)
{
if(user == null)
throw new ArgumentException("Invalid user","user");
CurrentUser = user;
}
}
This is just the most basic implementation of such a thing you can then check if CurrentUser
is null or not and direct user to login page or show her the results.
As your requirements grow you will need to implement more stuff. A logout, a local or remote database for users, store currently logged in user in disk so that she doesn't need to login again after closing the app and many other things
Edit
Based on your new information you can add this line to your login button click like this:
if (result.Rows.Count == 1)
{
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
//The rest of code
}
I have also presumed that you have a class like:
class User
{
public string Name { get; }
public int RoleId { get; }
public User(string name, int roleId)
{
Name = name;
RoleId = roleId;
}
}
And then you have to check Authentication.CurrentUser
against null
in your user form or admin form constructors to ensure user is login you can use the information in Authentication.CurrentUser
to show logged in user name or role or any other info.
I hope this helps you. If you need more info please say so.
edited Nov 23 '18 at 20:37
answered Nov 23 '18 at 18:25
EmadEmad
2,48822033
2,48822033
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error onUser, Match and currentUser
...
– Emanula Sohn
Nov 23 '18 at 19:35
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
Getting error onAuthentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string ANDpublic static bool *Login*(User user)
-> not all code path return a value
– Emanula Sohn
Nov 23 '18 at 21:38
add a comment |
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error onUser, Match and currentUser
...
– Emanula Sohn
Nov 23 '18 at 19:35
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
Getting error onAuthentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string ANDpublic static bool *Login*(User user)
-> not all code path return a value
– Emanula Sohn
Nov 23 '18 at 21:38
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error on
User, Match and currentUser
...– Emanula Sohn
Nov 23 '18 at 19:35
Could you please tell me how I could implement the above code into the form that the user enter? Im getting error on
User, Match and currentUser
...– Emanula Sohn
Nov 23 '18 at 19:35
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
@EmanulaSohn See the edit please
– Emad
Nov 23 '18 at 20:37
Getting error on
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string AND public static bool *Login*(User user)
-> not all code path return a value– Emanula Sohn
Nov 23 '18 at 21:38
Getting error on
Authentication.Login(new User(result.Rows[0]["username"],result.Rows[0]["role_id"])
cannot convert from object to string AND public static bool *Login*(User user)
-> not all code path return a value– Emanula Sohn
Nov 23 '18 at 21:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451318%2fhow-to-check-if-user-is-log-in-once-enter-a-form-using-c-sharp-winform-only-no%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Fun fact: there is a WinForms tag you can attach to your post so that it gets the proper attention without all that noise in the title
– Nat Pongjardenlarp
Nov 23 '18 at 18:17
done thanks, but what about the question?
– Emanula Sohn
Nov 23 '18 at 18:20
For what I understand, you can create a class "User" that equals null when loading. But when the user is connected:
User user = new User(required information)
. So when you need to know if the user is connected or not, you just check:if(user == null)
– Olivier Belanger
Nov 23 '18 at 18:24
u mean I should add a user which username/password = null or something like that in my database?
– Emanula Sohn
Nov 23 '18 at 18:25
@EmanulaSohn look at Emad answer, you create a class with a username and password, and if the user enter the correct credentials, he can login.
– Olivier Belanger
Nov 23 '18 at 18:30