Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typical password-like input field #202

Open
tinchodias opened this issue Sep 12, 2024 · 13 comments
Open

Typical password-like input field #202

tinchodias opened this issue Sep 12, 2024 · 13 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@tinchodias
Copy link
Collaborator

@plantec how do you recommend implementing it?

@plantec
Copy link
Collaborator

plantec commented Sep 13, 2024

you ask how to hide the text of the password ?

@tinchodias
Copy link
Collaborator Author

tinchodias commented Sep 13, 2024 via email

@plantec
Copy link
Collaborator

plantec commented Sep 13, 2024

maybe there is a font for that

@Nyan11
Copy link
Collaborator

Nyan11 commented Sep 27, 2024

If you only change the font, could you copy/paste the password ?
If yes, would it make it a security issue ?

@tinchodias
Copy link
Collaborator Author

Both are good points :)

For Morphic backend, that is always a reference implementation, it is a font. See RubTextFieldMorph>>#beEncrypted:

beEncrypted
	encrypted := true.
	self textMorph font: (StrikeFont passwordFontSize: self theme textFont pointSize)

where that font is:
Screenshot 2024-09-27 at 13 05 56
I don't know of an existing analogous way to do it for Bloc.

In Morphic, you CAN copy to clipboard (and paste the entered string).

You can test it with:

m := SpRubTextFieldMorph new.
m encrypted: true.
m openInWindow.

and wrapped in Spec:

text := SpTextInputFieldPresenter new.
text bePassword.
text open.

As a reference in HTML, I tested the password input field in this webpage:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password
on a Macbook, in Chrome, Firefox and Safari. In all cases, the CMD+c was ignored.
This should be possible to implement. In Morphic, by avoiding the execution of RubTextEditor>>#copySelection when the shortcut is pressed, or when menu item pressed on context menu.

@plantec
Copy link
Collaborator

plantec commented Sep 28, 2024

security ?
ok disabling the shortcut can be done easily and it is mandatory to do it for a password textfield.
but it will very easy to hack any image with a script that catch the passwd textfield content ☺️

@tinchodias
Copy link
Collaborator Author

tinchodias commented Oct 1, 2024 via email

@plantec
Copy link
Collaborator

plantec commented Oct 19, 2024

@tinchodias would you introduce a ToPasswordTextField class ?

@tinchodias
Copy link
Collaborator Author

I did some steps on a prototype that handles events on text changing, and stores in an instvar the entered characters but replaces the text in the field with asterisks.

@tinchodias
Copy link
Collaborator Author

Thanks Alain @plantec for your help. For the record, this is a script that converts a text field as a password field:

| filterField |
filterField := ToTextField new withoutLineBreak.
filterField userData at: #input put: filterField text copy.

filterField addEventHandlerOn: AlbTextInsertedEvent do: [ :evt |
	| cursorPosition |
	(filterField userData at: #input)
		insertText: evt text at: evt index.
	cursorPosition := evt target cursor position.
	evt target selecter all; apply.
	evt target inserter
		atEnd;
		string: (String new: evt target text size withAll: $*);
		apply.
	evt target cursor position: cursorPosition ].

filterField addEventHandlerOn: AlbTextDeletedEvent do: [ :evt |
	| cursorPosition |
	(filterField userData at: #input)
		delete: evt fromIndex to: evt toIndex.
	evt target selecter all; apply.
	evt target inserter
		atEnd;
		string: (String new: evt target text size withAll: $*);
		apply.
	evt target cursor position: evt fromIndex - 1 ].

filterField addEventHandlerOn: AlbTextReplacedEvent do: [ :evt |
	(filterField userData at: #input)
		deleteAll;
		insertText: evt text at: 0.
	evt target selecter all; apply.
	evt target inserter
		atEnd;
		string: (String new: evt target text size withAll: $*);
		apply ].

filterField addEditorShortcut: (BlShortcutWithAction new
		 combination: BlKeyCombination return;
		 action: [ :event | (filterField userData at: #input) traceCr ];
		 yourself).

filterField openInSpace

Press enter to see the current password on Transcript.

This works:

  • Type character (at the end or anyware)
  • Delete character (idem)
  • Set password via text: API
  • Paste from clipboard
  • Bug? Copy (cmd+c) copies asterisks

@tinchodias
Copy link
Collaborator Author

I encapsulated that code into a custom handler... not sure if I do a PR like this or polish it more...

@tinchodias
Copy link
Collaborator Author

For the moment, it's all in this fileout. It includes an example on class-side.

ToPasswordFieldEventHandler.st.zip

@tinchodias
Copy link
Collaborator Author

Another version with a fix (it has another class name):
SpToploPasswordFieldEventHandler.st.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants