Reputation: 137
I create an application where i implement trial version code. My code is
public class Test {
public static void main(String[] args) {
int s = 2013;
int t = 9;
int u = 29;
Calendar expireDate = Calendar.getInstance();
expireDate.set(s,t,u);
if (Calendar.getInstance().after(expireDate)) {
JTextField username = new JTextField();
JTextField password = new JPasswordField();
Object[] message = {
"Username:", username,
"Password:", password
};
int option = JOptionPane.showConfirmDialog(null, message, "Enter your Registration Code here", JOptionPane.OK_CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
String a ="as", b = "sa";
if (username.getText().equals(a) && password.getText().equals(b)) {
System.out.println("Login successful");
JFrame frame = new JFrame("Test");
frame.setVisible(true);
frame.setSize(500, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
JButton button = new JButton("hello agin1");
panel.add(button);
button.addActionListener(new Action1());
JButton button2 = new JButton("hello agin2");
panel.add(button2);
} else {
System.out.println("login failed");
JOptionPane.showMessageDialog(null, "Not Valid");
}
} else {
System.out.println("Login canceled");
System.exit(1);
}
}else{
JFrame frame = new JFrame("Test");
frame.setVisible(true);
frame.setSize(500, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
JButton button = new JButton("hello agin1");
panel.add(button);
button.addActionListener(new Action1());
JButton button2 = new JButton("hello agin2");
panel.add(button2);
}
}
static class Action1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
}
I have to register every time when i open application after expire. But i want after registration never look for registration code any more. Please help.
Upvotes: 1
Views: 492
Reputation: 5612
As already mentioned, you'd need some sort of a persistence mechanism to keep track of "how much time" the user has left on his trial. This is totally prone to exploitation, though.
A safer way, although less robust, is to hard code a date object as part of your binary and then check to see if the user is still within the trial window. Keep in mind that this strategy would require some way of rewriting the hard coded part each time you distribute a copy of the trial app.
And regardless of how you choose to do it, make sure you have an encode / decode scheme of some sort so the user can't just decompile and own your software.
Upvotes: 0
Reputation: 32517
You cannot write 100% desktop in Java with some 'unlockable' features in way, that nobody will be able bypass your security credential checking. Due to java specification (bytecode) is is very easy to decompile standalone application sources, disable restrictions, recompile and voila - full version for free! I bet you are not using any obsfuscating mechanisms right? Well than, cracking it won't be a problem.
Upvotes: 2