|
Hi,
I want to edit a winform on using mode.Iwant o allow user to change the interace and add controls without modifying the source code for example add a text box to the interface without modifying the code.
modified 24-Jan-14 4:51am.
|
|
|
|
|
It's not that simple: You can add controls (or let your user add controls) very simply: just create a new control instance, and add it to the Form.Controls collection:
TextBox tb = new TextBox();
Controls.Add(tb); (You might want to set it's Size and Location properties, but that's up to you).
The problem is that that does nothing "real" to the form - it doesn't hook up any events, it doesn't use any text the user types into the textbox for anything. And it doesn't save it so it loads like that next time.
I think you need to either think a bit more about exactly what you are trying to do, or try to explain it rather better to us - because unless we have a good idea why you want to do this, we can't easily work out what it is you need help with.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I want to create an application Winform c# that allows to edit the name of a fields or add another control and without modifying the code like in Sharepoint we can add liste button without code
|
|
|
|
|
..are you merely asking permission, or is there a specific question in the pipeline?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I assume you mean that you want the end-user at run-time to be able to edit attributes of Forms and Controls, move Controls in Forms around, and add new Controls.
If that's correct, and this is a Windows Forms project:
1. To edit properties add a PropertyGrid to your Forms from the VS ToolBox 'All Windows Controls' panel.
Hide the PropertyGrid, and make it visible as needed, setting its 'SelectedObject property to a Control, or to the Form, as required.
2. Make your Controls movable by implementing the appropriate MouseDown, MouseUp, and MouseMove EventHandlers.
3. Create some UI for adding new Controls, present it to the user.
If you have specific questions about how to implement these techniques, I suggest you post them, along with code in progress, to one of the C# QA forums.
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Hi All,
I want to download the most recent file from a remote SFTP. To do SFTP, I am using WinSCP.
The latest file will be decided on timestamp concatenated with FileName i.e. "myfile_20140124".
suppose I have number of files available on SFTP like
myfile_20140117.xml
myfile_20140118.xml
myfile_20140123.xml
myfile_20140124.xml
myfile_20140122.xml
myfile_20140121.xml
so I want to download the most recent file i.e. myfile_20140124.xml
I am very new to C# code Please help me.
Note: I will use all this code in SSIS 2012.
Thanks
Rahul Vairagi
-----------------------------------
www.sqlserver2005forum.blogspot.com
|
|
|
|
|
Rahul, rather than using a command line utility, you can use the inbuilt FTP classes to achieve this. The basic class you are interested in is FtpWebRequest[^]. Using this, you can connect to an FTP site and then list the files (there's a Method called WebRequestMethods.Ftp.ListDirectory that you will be invoking to get these files. Now that you have your list of files, you just need to get a copy of each filename and strip out the filenames looking for the numbers at the end (don't get fancy and try regexes, simply iterate over the characters in the name until you get to the number). Find the largest number and you've got the one you're interested in.
|
|
|
|
|
Thank you Pete for your reply !!
actually I am not using .Net framework, only using C# code in SSIS which is having many limitations.
Anyway, I got my code and its working fine.
thanks again
Thanks
Rahul Vairagi
-----------------------------------
www.sqlserver2005forum.blogspot.com
|
|
|
|
|
This excellent Code Project FTP class works very well: Simple C# FTP Class[^]
(There's a slight bug, which is documented in the comments and is easy to fix; it's a one-word change.)
|
|
|
|
|
thank you Alan
Thanks
Rahul Vairagi
-----------------------------------
www.sqlserver2005forum.blogspot.com
|
|
|
|
|
Development Environment:
Microsoft Visual Studio 2010 Ultimate,
C#,
MySql
Hi, I've create a function in mysql which accept 3 parameter to validate username and password.
DELIMITER $$
USE `generalledger`$$
DROP FUNCTION IF EXISTS `fLogin_Check`$$
CREATE DEFINER=`root`@`localhost`
FUNCTION `fLogin_Check`
(mUserName VARCHAR(50),mUserPass VARCHAR(40),mUserKey VARCHAR(40)) RETURNS INT
BEGIN
DECLARE mCount INT;
SELECT COUNT(*) INTO mCount FROM userMaster
WHERE userName = mUserName
AND AES_DECRYPT(userPass, mUserKey) = UPPER( mUserPass);
IF mCount > 0 THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
END$$
DELIMITER ;
As you can see I am using AES_DECRYPT function of MySql to check password, because I've use AES_ENCRYPT for password when INSERT username and password to mysql table.
Now I need to call the function fLogin_Check in C#, which I am doing by using following class method:
public int CheckUser(string mUserName, string mPass, string mKey)
{
oCn = da.GetConnection();
int res;
if (oCn == null)
{
oCn.Open();
}
sInsProcName = "fLogin_Check";
insertcommand = new MySqlCommand(sInsProcName, oCn);
insertcommand.CommandType = CommandType.StoredProcedure;
insertcommand.Parameters.Add(new MySqlParameter("mRes", MySqlDbType.Int32, 0));
insertcommand.Parameters["mRes"].Direction = ParameterDirection.ReturnValue;
insertcommand.Parameters.Add("mUserName", MySqlDbType.VarChar, 50, mUserName);
insertcommand.Parameters.Add("mUserPass", MySqlDbType.VarChar, 40, mPass);
insertcommand.Parameters.Add("mUserKey", MySqlDbType.VarChar, 40);
insertcommand.Parameters["mUserKey"].Value = mKey;
res = insertcommand.ExecuteNonQuery();
return (res);
oCn.Close();
}
oCn is the connection abject which uses to call GetConnection method define in my DAL class and da is the object created from DAL class, use to opening and closing database connection.
Using following Global class I am storing username and password after user enter them, and then try to validating with fLogic_Check Mysql function:
public static class Globals
{
public static string userName;
public static string userPass;
public const string sKey = "AHMEDFINANCEICMAP1122";
}
sKey is the key I use to encrypt password when insert username. Now I am trying to use it in C# from Login Form when user enter Username and Password and click login button with following code:
private void btnCheck_Click(object sender, EventArgs e)
{
Globals.userName = txtUser.Text.ToString();
Globals.userPass = txtPass.Text.ToString();
if (fUser.CheckUser(Globals.userName, Globals.userPass, Globals.sKey) == 0)
{
MessageBox.Show("Invalid Username or Password.");
}
else
{
MessageBox.Show("Login Successfull");
}
}
It always return 0, means failed login. I've checked the Mysql function in MySql GUI and it works fine:
SELECT fLogin_Check("AHMED","AHMED1981","AHMEDFINANCEICMAP1122") FROM userMaster
Which successfully return 1, however it fails when calling in C#. I've also tried to access Parameter which I've comment out after failure...What am I doing wrong?
Please guide..
Ahmed
|
|
|
|
|
I do not know why your function fails, but I want to tell you that you use the wrong concept:
Passwords have to be salted and hashed, not encrypted!
|
|
|
|
|
Thanks for your reply...
I've found lots of suggestion for encrypt the password is far better then salted and hashed method..But for now that is not the matter, I am looking for solution for MySql function not working in C#. Any ideas/suggestion for that??
|
|
|
|
|
ahmed_one wrote: I've found lots of suggestion for encrypt the password is far better then salted and hashed method
Where? The consensus from every decent security expert is that salted hashed passwords are far superior to encrypted passwords.
Even if the encryption key isn't compromised, encryption tends to produce the same output given the same input, which can make it trivial to compromise a large number of user's passwords. For example: http://nakedsecurity.sophos.com/2013/11/04/anatomy-of-a-password-disaster-adobes-giant-sized-cryptographic-blunder/[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ahmed_one wrote: I've found lots of suggestion for encrypt the password is far better then salted and hashed method Anyone who understands the difference can point out that this is incorrect.
If you store my password (encrypted), then YOU (and your boss, and everyone else in your company, and all subcontractors, and the cleaning-lady when you're AFK) will be able to decrypt the password. Next to having access to all the data you're supposed to secure, there's a huge chance that the user recycled one of his old passwords. Enough databases leaked with encrypted passwords to give us a nice and huge dictionary.
Salt and hash, or omit the password entirely; the only thing worse than no security is a FALSE sense of security.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
when creating new user account the password is encrypted via AEC_ENCRYPT function of mysql using a secret key which is only known by me.
Let's say user James's account is created with:
Username: James
Password: somesecretword
Now when password is saved in mysql db using AES_ENCRYPT it becomes something like "$-3+%,%kjunbsnd". Now when validation procedure is called it is using the AES_DECRYPT function using same key only i know, which validates the password alongwith username..
My question is how can anyone including the cleaning lady find the actual password without knowing the secret key?
Please do not consider this reply as argue, I am only a beginner trying to learn from experience masters like you.
Thanks
Ahmed
|
|
|
|
|
ahmed_one wrote: using a secret key which is only known by me.
Bullshit! It's known by the system because the system needs the key to unencrypt the password. Can you GUARANTEE with YOUR LIFE that your system is unhackable and there is zero chance of anyone else getting that key?? If you answer yes, quit your job right now because you're lying to everyone, but even worse, you're lying to yourself.
ahmed_one wrote: Now when password is saved in mysql db using AES_ENCRYPT it becomes something like "$-3+%,%kjunbsnd". Now when validation procedure is called it is using the AES_DECRYPT function using same key only i know, which validates the password alongwith username..
This is completely INSECURE! The best security systems do NOT compare a typed password against a decrypted password. They compare a hashed password against the hash in the database. No decryption necessary and the passwords are never "out in the open" in decrypted form.
YOU ARE HELL BENT ON DOING THIS THE WRONG WAY! DON'T DO IT!
|
|
|
|
|
ahmed_one wrote: which is only known by me. That's the problem. You should not have access to other people's passwords, end of story.
ahmed_one wrote: I am only a beginner trying to learn from experience masters like you. If you did, you'd be asking for explanation on the salt.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
ahmed_one wrote: I've found lots of suggestion for encrypt the password is far better then salted and hashed method
Really? I'd be willing to bet every single one of those "suggestions" was written by a security moron. The problem with encrypting a password is that it can be unencrypted and therefor broken. A salted and hashed password cannot be reversed to get the original string, making it FAR more secure.
|
|
|
|
|
just to answer you question - ExecuteNonQuery() return the number of rows effected which is zero ! Try using ExecuteScalar() !
Shujaat
|
|
|
|
|
I am reading a file and extracting a string
AB01AN728930JJ7YI8
VD036583AH84000002
In this string we have differenct section like AB,01,AN728930,JJ7YI8 in one line second line has VD,036583,AH84,000002
now there will be predefined line and predefined sections in string and each section will have some common validation like length, data type etc.
What is the best way of processing the validation on each character set
|
|
|
|
|
Try regex, The 30 Minute Regex Tutorial[^]
This tutorial will take you more than 30 minutes to read and understand if you are the first timer.
Formulate the regex patterns according to your respective validation rules.
|
|
|
|
|
how to read character from a particular position to a particular position in REGEX
|
|
|
|
|
You don't. RegEx uses patterns to match against, not positions.
If you know the specific positions, then you can just use the Substring method of the String class to get it. Start at this position and return x number of characters.
|
|
|
|
|
How many variants are there on the split up of the string ? - you show two, ie,
If String Starts With 'AB', then Format is AB, XX, YYYYYYYY, ZZZZZZ
If String Starts With 'VD', then Format is VD, XXXXXX, YYYY, ZZZZZZ
Before you go reaching for Regex, Id almost be suggesting that you look at Recursive Descent Parsing, or a parser based on a Grammar, using ANTLR perhaps - this would allow you to have rules, validation built in
'g'
|
|
|
|
|