Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335263 - SWT.PASSWORD Allows Copy/Paste of Text Value
Summary: SWT.PASSWORD Allows Copy/Paste of Text Value
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.1   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P1 critical (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Scott Kovatch CLA
QA Contact: Felipe Heidrich CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-24 18:39 EST by Daniel Johnson CLA
Modified: 2011-01-31 12:33 EST (History)
4 users (show)

See Also:
eclipse.felipe: review+
gheorghe: review+


Attachments
Fix for HEAD (1008 bytes, patch)
2011-01-28 17:31 EST, Scott Kovatch CLA
no flags Details | Diff
Fix for 3.6.2 (1021 bytes, patch)
2011-01-28 18:13 EST, Scott Kovatch CLA
no flags Details | Diff
Carbon fix (762 bytes, patch)
2011-01-28 18:29 EST, Scott Kovatch CLA
no flags Details | Diff
Carbon fix for 3.6.2 (762 bytes, patch)
2011-01-28 18:32 EST, Scott Kovatch CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Johnson CLA 2011-01-24 18:39:52 EST
Creating a new Text field with style SWT.PASSWORD does not keep the user from doing a normal copy/paste of the password value to another text field to reveal the true password. Is there any plan in the future to not let a user copy the value in a SWT.PASSWORD styled text field? Or is it up to implementers to override the behavior? If so what is the recommended way of doing this? Obviously can't just listen for cmd+c or cmd+x as copy/paste commands could change.
Comment 1 Scott Kovatch CLA 2011-01-28 14:30:41 EST
It looks like this is only in Carbon, correct? I can't reproduce it with 3.7 HEAD of Cocoa.

I consider this a serious bug, and not something a developer should have to worry about.
Comment 2 Daniel Johnson CLA 2011-01-28 14:45:53 EST
I am running 10.6.6. I haven't tried 3.7 HEAD. If I have time I will try to give it a shot. Jar in question: org.eclipse.swt.cocoa.macosx.x86_64_3.6.1.v3655c.jar
code snippet:
This is a sample createSection method from extending org.eclipse.wst.server.ui.editor.ServerEditorSection
public void createSection(Composite parent) {
    super.createSection(parent);
    FormToolkit toolkit = getFormToolkit(parent.getDisplay());
    Section section = toolkit.createSection(parent, Section.TWISTIE | Section.EXPANDED);
    section.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    Composite comp = toolkit.createComposite(section);
    toolkit.createText(comp, "", SWT.PASSWORD | SWT.SINGLE | SWT.BORDER);
}
Comment 3 Scott Kovatch CLA 2011-01-28 17:24:32 EST
Actually, this snippet will reproduce it in 3.6.1 and 3.7:


/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * Button example snippet: set the default button
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;

public class PasswordCopyTest {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	Label label = new Label (shell, SWT.NONE);
	label.setText ("Enter your password:");
	final Text text = new Text (shell, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD);
	text.setLayoutData (new RowData (100, SWT.DEFAULT));
	Button copy = new Button (shell, SWT.PUSH);
	copy.setText ("Copy");
	copy.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			text.selectAll();
			text.copy();
		}
	});
	Button cut = new Button (shell, SWT.PUSH);
	cut.setText ("Cut");
	cut.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			text.selectAll();
			text.cut();
		}
	});
	shell.setDefaultButton (cut);
	shell.setLayout (new RowLayout ());
	shell.pack ();
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
Comment 4 Scott Kovatch CLA 2011-01-28 17:31:05 EST
Created attachment 187888 [details]
Fix for HEAD

Fix based on HEAD from 1/28/11. This should go into the 3.6 stream, too.
Comment 5 Scott Kovatch CLA 2011-01-28 18:13:14 EST
Created attachment 187892 [details]
Fix for 3.6.2

Essentially the same patch for 3.6 branch.
Comment 6 Scott Kovatch CLA 2011-01-28 18:29:56 EST
Created attachment 187893 [details]
Carbon fix

Carbon has the same bug for cut(). copy() was taken care of in bug 243012.
Comment 7 Scott Kovatch CLA 2011-01-28 18:32:19 EST
Created attachment 187894 [details]
Carbon fix for 3.6.2

Same patch as Carbon HEAD.
Comment 8 Bogdan Gheorghe CLA 2011-01-31 11:43:31 EST
Scott, if you could get this out today that would be great. I'd like to do a 3.6.2 build submission tonight. Thanks!
Comment 9 Scott Kovatch CLA 2011-01-31 12:33:58 EST
Thanks, guys!

Fixed in Carbon and Cocoa for R_3_6_maintenance and HEAD > 20110131.